Applescript dialog button that opens a folder

Hi, I'm struggling with a script I am trying to write in the applescript editor. I am trying to write a script that backs up my USB stick when I mount it on my mac which works in conjunction with DoSomeThingWhen, a technique I found online. I am a total beginner to the applescript editor and this is the first script I am writing. Here is what I have so far:


do shell script ¬

"rsync -rt /Volumes/'USB DRIVE'/ ~/'USB Backup'"

display dialog "USB DRIVE has been backed up" buttons {"Dismiss", "Open"} default button "Dismiss"

if "Open" then open location "/Volumes/'USB DRIVE'/"



The script is working in that it backs up the drive when I mount it however I wanted to change the default buttons from "ok" and "cancel" to "dismiss" (replacing "ok") and "open" which opens the drive in finder. It is this "open" button which I am having trouble with and i would appreciate any help.


Thanks, Adam

MacBook Pro (Retina, Mid 2012), OS X Mountain Lion (10.8.2)

Posted on Feb 24, 2013 4:41 AM

Reply
10 replies

Feb 24, 2013 5:35 AM in response to Frank Caggiano

Thanks for the help but still won't open the folder. When i compile the script it places "if" at the end. Is there something else necessary?


Also have I inserted your lines correctly:


do shell script ¬

"rsync -rt /Volumes/'USB DRIVE'/ ~/'USB Backup'"

display dialog "USB DRIVE has been backed up" buttons {"Dismiss", "Open"} default button "Dismiss"


if the button returned of result = "Open" then


open location "/Volumes/'USBDRIVE'/"


end if

Feb 24, 2013 5:46 AM in response to adamk71

Not opening the folder is a different issue.


In your first example you weren't even checking if the display dialog returned the 'open' button correctly.


As for opening a location do you mean having a Finder window open on the folder? If so something like



display dialog "USB DRIVE has been backed up" buttons {"Dismiss", "Open"} default button "Dismiss"


if the button returned of result = "Open" then

tell application "Finder"

open ""/Volumes/'USBDRIVE'/" as alias

end tell


end if




should do it. You need to direct the open comand to the application that will perform the task. To Applescript open means to open a file not display it in a Finder window.


regards

Feb 24, 2013 6:27 AM in response to Frank Caggiano

The volume has a space and this space appears everwhere in my code:


do shell script ¬

"rsync -rt /Volumes/'USB DRIVE'/ ~/'USB Backup'"

display dialog "USB DRIVE has been backed up" buttons {"Dismiss", "Open"} default button "Dismiss"


if the button returned of result = "Open" then

tell application "Finder"

open "/Volumes/USB DRIVE/" as alias

end tell


end if


And here is the error message:


AppleScript Error


File /Volumes/USB DRIVE/ wasn’t found.


I should note that even if i change the folder or file to open to anything else such as my documents folder or a specific document I get the same error message.

Feb 24, 2013 10:17 AM in response to adamk71

Just for clarification, the actual problem with the original script is the use of the 'open location' command.


Open location requires a URL. You didn't provide a URL, just a text string that looks somewhat like a UNIX path.


The revised/working script uses the 'open' command, which is completely different. 'open' can open almost anything it recognizes as long as it's a recognizable path. The trick here is in properly identifying the item to open, which is compounded by AppleScript's sometime-love of UNIX (/-delimited) and Mac (colon-delimited) paths.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript dialog button that opens a folder

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.