Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Applescript > Re: Hi everyone
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 6 Topic 1556 of 1643
Post > Topic >>

Re: Hi everyone

by Jolly Roger <jollyroger@[EMAIL PROTECTED] > Dec 31, 2007 at 02:56 PM

In article 
<f001d333-3a2d-4996-87cd-0a838576a5bf@[EMAIL PROTECTED]
>,
 matt.philip@[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
 




 6 Posts in Topic:
Hi everyone
matt.philip@[EMAIL PROTEC  2007-12-31 11:28:12 
Re: Hi everyone
matt.philip@[EMAIL PROTEC  2007-12-31 12:06:26 
Re: Hi everyone
Jolly Roger <jollyroge  2007-12-31 14:56:34 
Re: Hi everyone
matt.philip@[EMAIL PROTEC  2007-12-31 13:15:55 
Re: Hi everyone
Durham Animation <matt  2007-12-31 17:27:24 
Re: Hi everyone
Jolly Roger <jollyroge  2007-12-31 21:30:09 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 13:38:39 CDT 2008.