I’m a total newbie to this, but I’m trying to create a script that will move a file to another computer over my airport network. Since the network is managed by dhcp, is it possible to write the script without using a specific ip address?
I have a script that I’m trying to get to work, even using a specific ip, but I’m not having any luck at getting it to move the file. I get an error that says the finder can’t get the folder on the server.
tell application "Finder"
try
mount volume "darronjeans" on server "10.0.1.2"
end try
move "/Users/darronjeans/Desktop/O&A/test.txt" to folder "afp://10.0.1.2/darronjeans/Desktop/O&A:"
end tell
Hopefully it’s not confusing that the paths are very semilar. One computer is my old laptop, the other is my new laptop, which is why the paths look similar on both.
This just a part of a larger script that I’m writing, but I can’t get past this hurdle.
Any help would be greatly appreciated.
Thanks
darron
Browser: Safari 525.20.1
Operating System: Mac OS X (10.5)
Move is a verb for repositioning objects on the screen. Use duplicate (in a Finder tell block with a colon-delimited path) or use do shell script “mv PosixPathToSource PosixPathToDestination”. See the man page for mv (In Terminal man mv) because across networks it’s a much better way to go than to have the Finder do it. Use cp if you want to copy source to destination rather than move it.
Not sure I understand how to use the shell script properly.
Tested it out, and was able to move a file from one computer to the other when the file name was known, but in the final script, i wont know the specific file name ahead of time.
I guess it might help to tell you what I’m trying to do.
I have Audio Hijack Pro recording a radio show at night on my computer that is always on my home network. (the radio show starts while I’m still at work, but by the time it finishes, I’m at home in bed, and my other ‘main laptop’ is now home too, connected to the network). When the recording finishes, Audio hijack pro will launch a script. I would like it to mount my main laptop, copy over the file it just finished recording to a folder that I have attached a folder action to that then adds it to itunes and syncs it to my iphone. So far, everything works except getting it to copy over the file.
Here is the full script that I have been trying to get working
property dest_folder : "afp://10.0.1.2/darronjeans/Desktop/O&A:"
on process(theArgs)
tell application "Finder"
try
mount volume "darronjeans" on server "10.0.1.2"
end try
end tell
--only way I could figure out how to get rid of the "Welcome to my world, I'm watching you dialog"
tell application "System Events"
delay (5)
--give it time to mount the server
keystroke return
end tell
tell application "Finder"
repeat with theFile in theArgs
move theFile to dest_folder
end repeat
end tell
end process
I came up with this script by modifying a script on Rogue Amoeba’s website for adding files to itunes, which is basically what I’m trying to do, but iTunes on a different computer.
Here’s their script
on process(theArgs)
--Into iTunes ye files shall go
tell application "iTunes"
repeat with theFile in theArgs
add theFile
end repeat
end tell
end process
because POSIX paths (slash separated) start always with / (start volume) or /Volumes/ (other volumes)
try something like this, adjust the properties user_name and pass_word or leave them empty (“”) to evoke the authentication window.
The handler returns true, if everything worked fine, or false, if an error occured theArgs can be a list of HFS paths, Finder file specifiers or aliases
property dest_folder : "/Volumes/darronjeans/Desktop/O&A"
property volume_name : "darronjeans"
property user_name : "user"
property pass_word : "¢¢¢¢"
on process(theArgs)
try
mount volume "afp://" & user_name & ":" & pass_word & "@10.0.1.2/" & volume_name
repeat until volume_name is in (do shell script "/bin/ls /Volumes")
delay 1
end repeat
set theSource to ""
repeat with theFile in theArgs
set theSource to theSource & quoted form of POSIX path of (theFile as alias) & space
end repeat
do shell script "/bin/cp -p " & theSource & dest_folder
return true
on error
return false
end try
end process
I tried your script as written, and it mounted my other laptop, but no files were transferred. Which is where I was at with the other script. I’m thinking now it must have something to do with processing theArgs. I messed around with it last night and couldn’t even get a simple script working that would move files from one folder to another on the same laptop when Audio Hijack finished recording.
I’ve been playing around with move file (theFile’s contents) right now, but getting an error that says “Sestem Events got an error: Can’t make alias"Macintosh HD:Users:darronjeans:Desktop:O&A:test.m4a" into type integer” Error Code -1753.
I was using my original script, not the one you posted, as I wasn’t quite sure how to modify yours.
Here it is. I removed the trying to get it to upload over the network to another computer down to just trying to get it to move it to another folder on the same computer to make sure that works first, which so far it hasn’t.
Here it is.
property dest_folder : "Users:darronjeans:Desktop:O&A:new:"
on process(theArgs)
--Coerce args to be a list
if class of theArgs is not list then
set theArgs to {theArgs}
end if
Tell application "Finder"
repeat with theFile in theArgs
move file (theFile's contents) to dest_folder
end repeat
end tell
end process
That’s the whole script as I have it right now. Am I leaving out something important?
Rogue Amoeba’s example script for adding files to iTunes is this
on process(theArgs)
--Into iTunes ye files shall go
tell application "iTunes"
repeat with theFile in theArgs
add theFile
end repeat
end tell
end process
It works for moving files into the iTunes library of that computer. Not sure what the main routine is. . .
Forget the handler. You found this somewhere but don’t have the run handler
Try this script, it prompts you to choose a couple of files
and moves (actually copies) the files to the shared volume.
Instead of the literal IP-Address you can also use the Bonjour name of the server with appended .local.
For example, if the name of the server is also darronjeans, you can use
afp://user:pass@darronjeans.local/myVolume
property dest_folder : "/Volumes/darronjeans/Desktop/O&A"
property volume_name : "darronjeans"
property user_name : "user"
property pass_word : "¢¢¢¢"
set theFiles to choose file with multiple selections allowed without invisibles
try
mount volume "afp://" & user_name & ":" & pass_word & "@10.0.1.2/" & volume_name
repeat until volume_name is in (do shell script "/bin/ls /Volumes")
delay 1
end repeat
set theSource to ""
repeat with oneFile in theFiles
set theSource to theSource & quoted form of POSIX path of oneFile & space
end repeat
do shell script "/bin/cp -p " & theSource & dest_folder
-- return true
-- on error
-- return false
end try
That kinda worked. It put the file on the desktop of the other computer, but not in the O&A folder, and the file name was only the first letter of the original file name. I guess I may be out of luck with this, as the intent was to have it do all of the work unattended while I sleep.
I found some documentation on Audio Hijack. Does this answer your question about the process routine?
They again show the following as an example of a script for adding files to iTunes.
on process(theArgs)
--Into iTunes ye files shall go
tell application "iTunes"
repeat with theFile in theArgs
add theFile
end repeat
end tell
end process
I figured out how to get Audio Hijack Pro to move files in the post processing stage.
property the_folder : "Macintosh_HD:Users:user_name:Desktop:O&A"
on process(theArgs)
tell application "Finder"
move theArgs to folder the_folder with replacing
end tell
end process
Seems simple enough now that I have figured it out. It’s late so I’ll work on putting that into the rest of the script to have it upload to the other computer tomorrow, but I just wanted to share my tiny breakthru.
Now knowing how to get Audio Hijack pro to move files on the same computer, I figured it would be easy to do it over the network, but I can’t seem to get it to work. I can get the server to mount, but try as I might, no files are copied.
Here it is in case anyone else is looking to do the same thing.
on process(theArgs)
--Mount the remote drive
tell application "Finder"
try
mount volume "darronjeans" on server "10.0.1.2"
end try
end tell
--only way I could figure out how to get rid of the "Welcome to my world, I'm watching you dialog"
tell application "System Events"
delay (5)
--give it time to mount the server
keystroke return
end tell
--copy the file that Audio Hijack Pro just finished recording to my folder on the remote hard drive
do shell script "/bin/cp " & quoted form of POSIX path of theArgs & space & "Volumes/darronjeans/Desktop/OnA/Test/"
end process
On the other computer I have a folder action attached to the folder that then adds the file to itunes, sets a few options for the file, then updates my iPhone, all with no interaction from me. By the time I wake up, I’m ready to listen to the latest recording on my way to work.