Jono Posted July 26, 2013 Share Posted July 26, 2013 I don't know much AppleScript and I'm trying to cobble together an action where I'd bring up a file in Alfred, Tab and select an action that would copy the selected file to the Desktop on another Mac on the network (it checks if the share is already mounted, and if not mounts it before copying the file over). I got the AppleScript to work in AppleScript Editor but am having trouble adapting it to work as an Alfred action. Here's the AppleScript that works in AppleScript Editor: -- Check the disk is mounted set myDisk to "Macmini" set mountedDisks to paragraphs of (do shell script "/bin/ls /Volumes") if myDisk is not in mountedDisks then mount volume "afp://Mac-mini.local/" & myDisk as user name "MYUSERNAME" with password "MYPASSWORD" end if tell application "Finder" set theFile to item 1 of (get selection) try duplicate theFile to "Macmini:Desktop:" with replacing on error errorMsg display alert errorMsg end try end tell For the Alfred action workflow I'm trying: on alfred_script(q) -- Check the disk is mounted set myDisk to "Macmini" set mountedDisks to paragraphs of (do shell script "/bin/ls /Volumes") if myDisk is not in mountedDisks then mount volume "afp://Mac-mini.local/" & myDisk as user name "MYUSERNAME" with password "MYPASSWORD" end if tell application "Finder" try duplicate q to "Macmini:Desktop:" with replacing on error errorMsg display alert errorMsg end try end tell end alfred_script I've tried it as /usr/bin/osascript and Run NSAppleScript without any luck. Any help would be greatly appreciated. Link to comment
Tyler Eich Posted July 27, 2013 Share Posted July 27, 2013 (edited) I don't know much AppleScript and I'm trying to cobble together an action where I'd bring up a file in Alfred, Tab and select an action that would copy the selected file to the Desktop on another Mac on the network (it checks if the share is already mounted, and if not mounts it before copying the file over). I got the AppleScript to work in AppleScript Editor but am having trouble adapting it to work as an Alfred action. Here's the AppleScript that works in AppleScript Editor: -- Check the disk is mounted set myDisk to "Macmini" set mountedDisks to paragraphs of (do shell script "/bin/ls /Volumes") if myDisk is not in mountedDisks then mount volume "afp://Mac-mini.local/" & myDisk as user name "MYUSERNAME" with password "MYPASSWORD" end if tell application "Finder" set theFile to item 1 of (get selection) try duplicate theFile to "Macmini:Desktop:" with replacing on error errorMsg display alert errorMsg end try end tell For the Alfred action workflow I'm trying: on alfred_script(q) -- Check the disk is mounted set myDisk to "Macmini" set mountedDisks to paragraphs of (do shell script "/bin/ls /Volumes") if myDisk is not in mountedDisks then mount volume "afp://Mac-mini.local/" & myDisk as user name "MYUSERNAME" with password "MYPASSWORD" end if tell application "Finder" try duplicate q to "Macmini:Desktop:" with replacing on error errorMsg display alert errorMsg end try end tell end alfred_script I've tried it as /usr/bin/osascript and Run NSAppleScript without any luck. Any help would be greatly appreciated. It looks like you forgot to make q a file object; when you get the selection from Finder, it returns a file object automatically. Maybe try changing this: try duplicate q to "Macmini:Desktop:" with replacing to this: try duplicate ((POSIX file q) as alias) to ("Macmini:Desktop:" as alias) with replacing I got this answer from Stack Overflow Make sure you run this in the 'Run NSAppleScript' object; '/usr/bin/osascript' will not perform as expected. Cheers Edited July 28, 2013 by Tyler Eich Jono 1 Link to comment
Jono Posted July 27, 2013 Author Share Posted July 27, 2013 (edited) Thanks for the help. I tried that (and a few variations of it), but unfortunately it still wouldn't work. It showed a message from Finder: Finder got an error: Can't set "Macmini:Desktop:" to POSIX file "/Users/Jono/Desktop/test_file.png". Edited July 27, 2013 by Jono Link to comment
Tyler Eich Posted July 28, 2013 Share Posted July 28, 2013 Thanks for the help. I tried that (and a few variations of it), but unfortunately it still wouldn't work. It showed a message from Finder: Finder got an error: Can't set "Macmini:Desktop:" to POSIX file "/Users/Jono/Desktop/test_file.png". Oops! I updated my original response; see if that new code works for you Cheers Jono 1 Link to comment
Jono Posted July 28, 2013 Author Share Posted July 28, 2013 That's it! Works perfectly now, thanks! Tyler Eich 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now