On Dec 31, 3:56 pm, Jolly Roger <jollyro...@[EMAIL PROTECTED]
> wrote:
> In article
> <f001d333-3a2d-4996-87cd-0a838576a...@[EMAIL PROTECTED]
>,
>
>
>
> matt.phi...@[EMAIL PROTECTED]
wrote:
> > On Dec 31, 2:28 pm, matt.phi...@[EMAIL PROTECTED]
wrote:
> > > I'm new to applescript and I need some help :D
>
> > > what I plan to do is make an app. for image conversion.
>
> > > steps the app will take:
>
> > > - file will be dropped on script
> > > - app. will take file (with variable name) and send it to the
terminal
> > > - a conversion application will be launched by the terminal imputing
> > > the file name of the file dropped on the script
> > > - this will run and output a file to the /user dir
> > > - the script will now move that file back to the dir where the
script
> > > is located
>
> > > the image converter is packaged with a program called maya and is
> > > called IMF_copy
>
> > > any help or a starting point would be awesome
>
> > > thanks
>
> > > Matt
>
> > the command I use in the terminal now to covert an image
> > "mattphilip$ /Applications/Autodesk/maya8.5/Maya.app/Contents/bin/
> > imf_copy -v -p -L /giantskined1001+R32.tif giantnew.map"
>
> > the image converter is packaged with a program called maya and is
> > called IMF_copy
>
> > (giantskined1001+R32.tif giantnew.map) are just names of images this
> > would be based on the file dropped on the script
>
> You'll want to create a droplet script. To do so, create a normal script
> in Script Editor and add a "on open" handler. In this handler, your
> script will process the dropped items using the "do shell script"
> command to run your shell script, inserting the names of the target and
> destination image/map into the command each time. I suggest you
> calculate the file name of the destination file based on the source file
> name each time. Take a look at the Standard Additions AppleScript
> Dictionary for the specific syntax of "do shell script" (In Script
> Editor, File > Open Dictionary). Here's some (really rough and
> incomplete) code to get you started:
>
> -- begin script
> on open fileList
> -- droplet entry - process dropped items
> repeat with nextItem in fileList
> if the last character of (nextItem as text) is ":" then
> my ProcessFolder(nextItem)
> else
> my ProcessFile(nextItem)
> end if
> end repeat
> end open
>
> on ProcessFolder(someFolder)
> tell application "Finder"
> set allFiles to the entire contents of someFolder
> end tell
> repeat with nextItem in allFiles
> if the last character of (nextItem as text) is not ":" then
> my ProcessFile(nextItem)
> end if
> end repeat
> end ProcessFolder
>
> on ProcessFile(someFile)
> set sourceName to my FilenameFromPath(someFile)
> set sourceFolder to my ParentFromPath(someFile, true)
>
> set sourcePath to someFile's POSIX path
> set destPath to (sourceFolder's POSIX path & my
> ChangeExtension(sourceName, ".map"))
>
> set command to
> "/Applications/Autodesk/maya8.5/Maya.app/Contents/bin/imf_copy -v -p -L
> " & the quoted form of sourcePath & " " & the quoted form of destPath
>
> set the result to do shell script command
>
> -- check the result for errors
> end ProcessFile
>
> on FilenameFromPath(thePath)
> set oldDelimiters to AppleScript's text item delimiters
> set AppleScript's text item delimiters to ":"
> set pathAsList to text items of (thePath as text)
> if the last character of (thePath as text) is ":" then
> set idx to -2 -- (the number of text items in thePath) - 1
> else
> set idx to -1
> end if
> set filename to item idx of pathAsList
> set AppleScript's text item delimiters to oldDelimiters
> return filename
> end FilenameFromPath
>
> on ParentFromPath(thePath, wantPath)
> set thePath to (thePath as text)
> set saveDelim to AppleScript's text item delimiters
> set AppleScript's text item delimiters to {":"}
> set pathAsList to text items of thePath
> if the last character of thePath is ":" then
> set idx to (the number of text items in thePath) - 2
> else
> set idx to -2
> end if
> if wantPath then
> set folderName to ((text items 1 through idx of pathAsList) as
> text) & ":"
> else
> set folderName to item idx of pathAsList
> end if
> set AppleScript's text item delimiters to saveDelim
> return folderName
> end ParentFromPath
>
> on ChangeExtension(filename, newExtension)
> set saveDelims to AppleScript's text item delimiters
> set AppleScript's text item delimiters to {"."}
> set itemList to (every text item of filename)
> set AppleScript's text item delimiters to saveDelims
> set justTheName to item 1 of itemList
> -- do not overflow - filename + .ext must < 31 characters (Mac OS 9
> sup****t)
> set nameLength to the (count of justTheName)
> set extLength to the (count of newExtension) + 1
> if the nameLength > (31 - the extLength) then
> set justTheName to (characters 1 thru (31 - the extLength) of
> justTheName) as text
> end if
> if newExtension starts with "." then
> return justTheName & newExtension
> else
> return justTheName & "." & newExtension
> end if
> end ChangeExtension
> -- end script
>
> You can download a zipped script with this code here:
>
> <http://jollyroger.kicks-ass.org/jollyroger/droplet.zip>
>
> --
> Note: Please send all responses to the relevant news group. If you
> must contact me through e-mail, let me know when you send email to
> this address so that your email doesn't get eaten by my SPAM filter.
>
> JR
holy crap!! your script works perfect! I don't understand it
completely but I've tested it and it works like a dream. I would like
to share this with the zbrush community at http://www.zbrushcentral.com
if you don't mind, I will of course give you all the credit and plug
your site or do something for you. let me know what you think, this is
something a lot of us right brained folk have been trying to do for a
while now.
Thanks this is something I've been struggling with for 2 months now
Matt


|