2016-06-13 61 views
2

使用Finder時,腳本可能需要很長時間。我也想讓這個腳本在後臺工作。如何在此腳本中使用System Events/bash而不是Finder?AppleScript:使用系統事件或bash移動文件

property source_folder_one : alias "OS X:Users:username:Pictures:Work:New:one" 
property source_folder_two : alias "OS X:Users:username:Pictures:Work:New:two" 
property save_folder_one : alias "OS X:Users:username:Pictures:Work:Waitlist:one" 
property save_folder_two : alias "OS X:Users:username:Pictures:Work:Waitlist:two" 

tell application "Finder" 
    move entire contents of folder source_folder_one to folder save_folder_one 
    move entire contents of folder source_folder_two to folder save_folder_two 
end tell 

display notification "All images were relocated." with title "Relocating Complete" sound name "Glass.aiff" 
tell me to quit 
+0

AppleScript不支持使用多線程,對於後臺任務等不是一個好選擇。使用bash中的幾行代碼很容易,然後將其另存爲.command。 –

+1

使用帶有unix命令'mv'的do shell腳本命令來移動所有文件(使用名稱爲*。*的文件夾從文件夾A移動到文件夾B)。它是在後臺和shell級別(最快的方式)完成的。 – pbell

+0

你能幫我做到嗎?我從來沒有在bash上寫過任何東西。 –

回答

0

我做了一個applescript,做你想做的。 但是對於一個文件夾而不是兩個,您可以在提示中選擇文件夾。

set sourceFolder to (choose folder) as alias 
set saveFolder to (choose folder) as alias 
set sourceFolderPOSIXPath to (the POSIX path of sourceFolder) 
set saveFolderPOSIXPath to (the POSIX path of saveFolder) 

set shellString to "mv " & sourceFolderPOSIXPath & "* " & saveFolderPOSIXPath 
do shell script shellString 

display notification "All files were relocated." with title "Relocating Complete" sound name "Glass.aiff" 

如果你想使用你不斷的別名,只是"OS X:Users:username:Pictures:Work:New:one"等取代(choose folder)

+0

完美工作!謝謝!我可以在那裏添加第二個文件夾,它也可以工作! –

相關問題