2012-09-06 48 views
0

我必須將文件複製到很多USB棒。所以我想給我寫一個簡短的蘋果。我不熟悉applescript,所以如果有人能給我一些提示,那將會很棒。使用AppleScript將文件複製到多個USB棒

我有什麼至今:

10位USB-集線器

短的腳本來重命名棒。

現在I'm停留在複製文件到連接每棒:

property ignoredVolumes : {"Macintosh HD", "Time Machine Backups"}  

set myPath to ("Macintosh HD:Users:myusername:USB-Stick") as string 
tell application "System Events" 
set rootVolume to disk item (POSIX file "/Volumes" as text) 
set allVolumes to name of every disk item of rootVolume 
repeat with aVolume in allVolumes 
    if aVolume is not in ignoredVolumes then 
     set name of disk item (path of rootVolume & aVolume) to "Stickname" 
    end if 
end repeat 
end tell 

我現在需要做的是從mypath中複製到一個連接每個USB棒。因爲他們都獲得相同的名稱,他們將掛載名稱後面的數字(Stickname,Stickname 1,Stickname 2,...)

因此,我需要在我的循環中將複製命令添加到剛更名的棒。

希望有人能給我一個援助之手。

回答

1

它會更容易用shell腳本來完成:

do shell script "cp -R ~/USB-Stick/ /Volumes/Stickname*" 
+0

嗨Lri,謝謝!我會嘗試。 KR – solick

+0

進行了一些修改,正是我一直在尋找的... – solick

1

你可以嘗試這樣的事情:

property ignoredVolumes : {"Macintosh HD", "Time Machine Backups", "iDisk", "net", "home"} 
set myPath to (path to home folder as text) & "USB-Stick:" 
tell application "System Events" to set theDisks to every disk 
repeat with aDisk in theDisks 
    if aDisk's name is not in ignoredVolumes then 
     set diskPath to path of aDisk 
     tell application "Finder" to duplicate myPath to diskPath with replacing 
    end if 
end repeat 
0

感謝您的提示。我現在用下面的代碼解決它:

property ignoredVolumes : {"Macintosh HD", "Time Machine Backups"} -- add as needed 
property counter : 0 
tell application "System Events" 
set rootVolume to disk item (POSIX file "/Volumes" as text) 
set allVolumes to name of every disk item of rootVolume 
set StartTime to (get current date) 
repeat with aVolume in allVolumes 
    if aVolume is not in ignoredVolumes then 
     set newName to "XXX" & counter as string 
     log newName & " in Progress... " 
     set name of disk item (path of rootVolume & aVolume) to newName 
     set counter to counter + 1 
     set scr to ("cp ~/USB-Stick/* /Volumes/" & newName) 
     do shell script scr 
     set name of disk item (path of rootVolume & newName) to "XXX" 
     do shell script "diskutil unmount /Volumes/XXX" 
     log newName & " finished." 
    end if 
end repeat 
set endTime to (get current date) 
set dur to (endTime - StartTime) 
display dialog "Process took " & dur & "seconds." 
end tell 

希望這會幫助其他同樣的問題。

只有一個外觀問題:兩個shell腳本的調用會引發錯誤-10004,但仍然有效。嘗試告訴應用程序「Finder」或「終端」,但錯誤依然存在,並已被其他錯誤添加,所以我堅持我的原始解決方案。

親切的問候

相關問題