2017-02-09 96 views
0

我一直在試圖製作一個簡單的應用程序,它將選定的文件複製到預定的目錄,只有在shell腳本中設置該變量不起作用。我想知道是否有方法來複制或移動命令以使其生效。腳本如下。在執行shell腳本的過程中設置命令

set filepath to POSIX path of (choose file with prompt "Chose your file") 
delay 
do shell script "cp " & filepath & " ~/Library/Application Support/" 

回答

1

它不工作,因爲在路徑中的空格字符必須進行轉義,最可靠的方法是使用quoted form of

path to application support folder from user domain是當前用戶的應用程序支持文件夾的相對路徑。

set applicationSupportFolder to POSIX path of (path to application support folder from user domain) 
set filepath to POSIX path of (choose file with prompt "Chose your file") 
do shell script "cp " & quoted form of filepath & space & quoted form of applicationSupportFolder 
+0

感謝您的快速響應。這很好,我現在有程序工作!這正是我需要的!謝謝! – user7439349