My question: how do I do this from applescript? It would be cool for
me, if I could make it as a droplet - so I could the drop the folder
on it - and thereby have the first variable parsed - and then the
applescript could prompt me for the three remaining variables?
Is this possible in applescript?
Thanks a bunch.
Model: Macbook
AppleScript: 2.1.1(81)
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
on open fileList
set folderPath to quoted form of POSIX path of item 1 of fileList as string
set i to 0
set varString to ""
repeat
set i to i + 1
set varBoxResult to (display dialog "Enter variable " & i default answer "" buttons {"Cancel", "Done", "Another"} default button 3)
set varString to varString & " " & text returned of varBoxResult
if button returned of varBoxResult is "Done" then exit repeat
end repeat
set SC to "/path/to/scrptname.ksh " & folderPath & varString
--do shell script SC
display dialog SC
end open
Save it as an application and give it a test run… If the string displayed looks the way you want it too then comment out the display dialog and uncomment the do shell script line and resave.
Whats the full command it should be trying to run? When ran through the display does it appear correctly?
It should be important to note that when a AppleScript performs a “do shell” command the commands are ran within the “SH” shell not your default shell (whatever that may be). Perhaps your script needs a bit of tweaking… Be sure to specify full paths to commands.
The fulle command as I run it from the Terminal is:
/Users/hansen/Scripts/htmlgallery.ksh /Users/hansen/Desktop/engangskamera/ “Testevent” “17.02.2007”
If I run your script in the “display mode”, I get:
/Users/hansen/Scripts/htmlgallery.ksh ‘/Users/hansen/Desktop/engangskamera/’ Testevent 17.02.2007
well the quotes in the path shouldn’t matter at all… they are there on purpose in case you drop a folder with a space in the name since it won’t escape the space. I see you are putting quotes around your arguments though, so we can try that.
on open fileList
set folderPath to quoted form of POSIX path of item 1 of fileList as string
set i to 0
set varString to ""
repeat
set i to i + 1
set varBoxResult to (display dialog "Enter variable " & i default answer "" buttons {"Cancel", "Done", "Another"} default button 3)
set varString to varString & " " & quoted form of (text returned of varBoxResult)
if button returned of varBoxResult is "Done" then exit repeat
end repeat
set SC to "/path/to/scrptname.ksh " & folderPath & varString
--do shell script SC
display dialog SC
end open
It determines filetypes, makes image processing, copies pictures online and updates some indexes… almost 700 lines of shell script… It would be so nice if I could just drop a folder on to an icon, so I don’t have to open the terminal…
do shell script "/Users/hansen/Scripts/htmlgallery.ksh /Users/hansen/Desktop/engangskamera/ \"Testevent\" \"17.02.2007\""
That will send to the shell the exact syntax that works when you run it from the terminal itself. Lets start with that and see if that works… If it doesn’t then something about your script is bombing when being interpreted by the SH shell.
G R E A T !! - it worked, and I got my output in script editor:
Working in /Users/hansen/Desktop/westside
Determing filetype…
Type is: jpg
There are 10 jpg files in /Users/hansen/Desktop/westside
Working in /Users/hansen/Desktop/westside
Creating directory pages
Directory pages created
Creating directory thumbs
Directory thumbs created
Creating directory orgs
Directory orgs created
Working in /Users/hansen/Desktop/westside
Processing files of type: jpg…
Copying files to dir: orgs
Files copied to directory: orgs
Copying files to dir: thumbs
Files copied to directory: thumbs
Deleting original files
Original files deleted succesfully
Working in /Users/hansen/Desktop/westside
Creating thumbnails from originals…
Thumbnails created
etc etc…
So how do we transfer it in to at droplet?
And actually I only need to vars - besides the folder path.
on open fileList
set folderPath to quoted form of POSIX path of item 1 of fileList as string
set var1 to quoted form of text returned of (display dialog "Enter value for variable 1" default answer "")
set var2 to quoted form of text returned of (display dialog "Enter value for variable 2" default answer "")
do shell script "export TERM=xterm-color;/Users/hansen/Scripts/htmlgallery.ksh " & folderPath & " " & var1 & " " & var2
end open
Yes & No are the answer. You can’t do a progress bar with Vanilla AppleScript, but you can through either an Xcode project or through the use of a 3rd party progress app that you manipluate… An excelllent example, and one I used for quite a while, is Bruce Phillips Progress Bar - http://scriptbuilders.net/files/bpprogressbar1.0.html
The problem though I forsee is you would have to use a barber pole style indicator since you have the meat of the work being done in a shell script which cant communicate back to the progress bar. A better way perhaps, regardless of which progress approach you take, would be too make your shell script into an AppleScript… even if you end up doing multiple “do shell script” within the AppleScript. This way you could at least put progress updaters in as you see fit.