|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
Use applescript automatic copy Specified files from new added Mobile hard disk to mac
hi,guys
I use a 2012mac mini as a home server,after read some applescript introduce,I found a vast space about automatic processing on Mac OS. Now I am thinking use a applescript copy the specified files from new added Mobile hard disk to Mac mini when the new disck just connected to mac mini. For example: a USB hard drive have movie/music/pic/ folders,when it connected to mac mini,the script can automatic copy those folders' files to mac itself at different folders. If script can do more,I wonder it can identify different extend of files,that can make mkv/avi/rmvb as movie files copy to mac's movie folder,mp3/m4a as music files copy to music folder,so as pic. Expression may not be detailed,looking forward to your answers!
Last edited by woshiysc; Feb 19, 2013 at 06:51 AM. Reason: applescript folder |
|
|
|
0
|
|
|
#2 |
|
There's a couple of ways to do what you want. Applescript or a combination of Applescript and a LaunchAgent or another application or a System preference pane. You might want to take a look at DSW. Do Something When is a system preference pane that allows the user to watch for drives mounting and un-mounting, allowing them to launch or quit applications, when these events happen. This in combination with an Automator app or Applescript app should do the trick. You could do something like this with Automator actions :
Info : http://www.azarhi.com/Projects/DSW/index.php
__________________
Space Corps Directive 34124 Last edited by kryten2; Feb 20, 2013 at 01:33 PM. |
|
|
|
1
|
|
|
#3 | |
|
Quote:
It's really very helpful! But I still have two questions: 1.How can the script avoid copying same files when mounting USB drive times. 2.If I mount different drives with different names,can the Automator identify them and copy the files,I search the DSW and it may achieve this function,but I tend to use applescript or Automator release the function. ![]() Looking forward to your wonderful answer! |
||
|
|
0
|
|
|
#4 |
|
1) I may be wrong on this but if you check Replace existing files in the Copy Finder Items the file will be replaced. If you leave it unchecked and the file exists it will not be copied.
2) Make a rule in DSW for every external disk and for every rule make a workflow with changes made to the where part in the Find Finder Items pointing to the correct external disk. You're not the first person to ask to do something when a drive mounts. It can be done with Applescript but it will take some time and work from you to put it all together. You can also attach a folder action to the /Volumes folder. I've included some more info to get you started. Info : http://stackoverflow.com/questions/1...rt-a-usb-drive http://hintsforums.macworld.com/show...99&postcount=6
__________________
Space Corps Directive 34124 |
|
|
|
1
|
|
|
#5 | |
|
Quote:
I had aready thought about folder action,but don't know which folder to watch and the next steps! Those information are exactly in line with my idea! Thank you very much again,and I have to learn those data and release the idea on my Mac mini~
|
||
|
|
0
|
|
|
#6 |
|
See PM :
__________________
Space Corps Directive 34124 |
|
|
|
1
|
|
|
#7 |
|
|
0
|
|
|
#8 |
|
Hi,kryten
Through a day of hard work finally completed the script but with a big problem: error "System Events got an error: Can’t get path of folder \"Macintosh HD:Volumes:\"." number -1728 from path of folder "Macintosh HD:Volumes:" ![]() Code:
property ignoredVolumes : {"Macintosh HD", "BOOTCAMP"} -- add as needed
tell application "System Events"
set rootVolumes to disk item (POSIX file "/Volumes" as text)
set allVolumes to name of every disk item of rootVolumes
set numofallVolumes to count of allVolumes
set numofignoredVolumes to count of ignoredVolumes
set moviemacVolume to disk item (POSIX file "/Users/Shades/Desktop/test/movie" as text)
set musicmacVolume to disk item (POSIX file "/Users/Shades/Desktop/test/music" as text)
set picmacVolume to disk item (POSIX file "/Users/Shades/Desktop/test/picture" as text)
repeat with aVolume in allVolumes
tell application "Finder"
if aVolume is not in ignoredVolumes and numofallVolumes / numofignoredVolumes is not equal to 1 then
if exists (folder whose name is "mtmac" as text) of folder (path of rootVolumes & aVolume) then
set movieusbVolume to disk item (POSIX file "/mtmac/movie" as text)
set muciscusbVolume to disk item (POSIX file "/mtmac/music" as text)
set picusbVolume to disk item (POSIX file "/mtmac/picture" as text)
copy (file (path of rootVolumes & aVolume & movieusbVolume) whose kind is movie) to (path of moviemacVolume)
copy (file (path of rootVolumes & aVolume & muciscusbVolume) whose kind is movie) to (path of musicmacVolume)
copy (file (path of rootVolumes & aVolume & picusbVolume) whose kind is picture) to (path of picmacVolume)
beep 1
else if not (exists (folder whose name is "mtmac" as text) of folder (path of rootVolumes & aVolume)) then
display dialog "Without the specified folder,eject ?" buttons {"yes", "no"} default button "yes" with title "eject drives" giving up after 60
if button returned of result = "yes" then
eject aVolume
end if
beep 1
end if
end if
end tell
end repeat
beep 3
end tell
|
|
|
|
0
|
|
|
#9 |
|
这样写:
Code:
property ignoredVolumes : {"Macintosh HD", "BOOTCAMP"} -- add as needed
property videoExtensions : {"avi", "mov", "mpg", "mpeg", "wmv"}
property audioExtensions : {"mp3", "wav", "mp4", "aac", "m4a", "m4b"}
property imageExtensions : {"tif", "tiff", "gif", "png", "pict", "pct", "jpg", "jpeg"}
set moviemacVolume to alias (POSIX file "/Users/Shades/Desktop/test/movie")
set musicmacVolume to alias (POSIX file "/Users/Shades/Desktop/test/music")
set picmacVolume to alias (POSIX file "/Users/Shades/Desktop/test/picture")
tell application "System Events"
set rootVolumes to disk item (POSIX file "/Volumes" as text)
set allVolumes to name of every disk item of rootVolumes
set numofallVolumes to count of allVolumes
repeat with aVolume in allVolumes
display dialog aVolume as text
tell application "Finder"
if (aVolume is not in the ignoredVolumes and (aVolume as text) is not ".DS_Store") then
if exists alias (POSIX file ("/Volumes/" & aVolume & "/mtmac") as text) then
duplicate (items whose name extension is in the videoExtensions) in alias (POSIX file ("/Volumes/" & aVolume & "/mtmac/movie") as text) to moviemacVolume
duplicate (items whose name extension is in the audioExtensions) in alias (POSIX file ("/Volumes/" & aVolume & "/mtmac/music") as text) to musicmacVolume
duplicate (items whose name extension is in the imageExtensions) in alias (POSIX file ("/Volumes/" & aVolume & "/mtmac/picture") as text) to picmacVolume
beep 1
else
display dialog "Without the specified folder,eject?" buttons {"yes", "no"} default button 1 with title "eject drive" giving up after 60
if button returned of result is "yes" then eject aVolume
end if
end if
end tell
end repeat
end tell
|
|
|
|
0
|
|
|
#10 |
|
改了一下,这样比较不容易报错:
Code:
property ignoredVolumes : {"MountainLion", "Mariposa"} -- add as needed
property videoExtensions : {"avi", "mov", "mpg", "mpeg", "wmv"}
property audioExtensions : {"mp3", "wav", "mp4", "aac", "m4a", "m4b"}
property imageExtensions : {"tif", "tiff", "gif", "png", "pict", "pct", "jpg", "jpeg"}
set moviemacVolume to alias (POSIX file "/Users/Shades/Desktop/test/movie")
set musicmacVolume to alias (POSIX file "/Users/Shades/Desktop/test/music")
set picmacVolume to alias (POSIX file "/Users/Shades/Desktop/test/picture")
tell application "System Events"
set rootVolumes to disk item (POSIX file "/Volumes" as text)
set allVolumes to name of every disk item of rootVolumes
set numofallVolumes to count of allVolumes
repeat with aVolume in allVolumes
tell application "Finder"
if (aVolume is not in the ignoredVolumes and (aVolume as text) is not ".DS_Store") then
try
if exists alias (POSIX file ("/Volumes/" & aVolume & "/mtmac") as text) then set trk to 1
on error
set trk to 0
end try
if trk = 1 then
duplicate (items whose name extension is in the videoExtensions) in alias (POSIX file ("/Volumes/" & aVolume & "/mtmac/movie") as text) to moviemacVolume
duplicate (items whose name extension is in the audioExtensions) in alias (POSIX file ("/Volumes/" & aVolume & "/mtmac/music") as text) to musicmacVolume
duplicate (items whose name extension is in the imageExtensions) in alias (POSIX file ("/Volumes/" & aVolume & "/mtmac/picture") as text) to picmacVolume
beep 1
else
display dialog "Without the specified folder,eject?" buttons {"yes", "no"} default button 1 with title "eject drive" giving up after 60
if button returned of result is "yes" then eject aVolume
end if
end if
end tell
end repeat
end tell
|
|
|
|
0
|
|
|
#11 | |
|
Quote:
|
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 07:57 AM.









Linear Mode
