2017-05-14 46 views
0

我最近開始擺弄AppleScript,但我似乎無法讓我的腳本工作。但是,我沒有得到任何錯誤。腳本執行並且'沒有'發生。需要我的自定義AppleScript的一些觀點

tell application "Finder" 
set theWin to window 1 
set thePath to (POSIX path of (target of theWin as alias)) 
copy file "Macintosh HD:Users:thijmendam:Documents:NieuwBestandSource:Naamloos.pages" to thePath 
end tell 

我想要做的是將文件Naamloos.pages移動到當前打開的Finder窗口。如果我想將它複製到一個文件夾,這工作正常。但是,如果我使用路徑,'沒有'發生。 在例如,下面的腳本不工作:

'tell application "Finder" 
set theWin to window 1 
set thePath to (POSIX path of (target of theWin as alias)) 
copy file "Macintosh HD:Users:thijmendam:Documents:NieuwBestandSource:Naamloos.pages" to folder "this:is:a:destination:folder" 
end tell 

顯然,這不是我想要達到的目標。我只是不知道如何將文件複製到路徑。誰能幫我嗎?

乾杯!

回答

0

這是因爲你試圖使用POSIX路徑只是刪除

這裏有一個例子

tell application "Finder" 
set afile to (choose file) as alias 
set theWin to window 1 
set thePath to (target of theWin as alias) 
copy file afile to folder thePath 

末告訴所有正確的命令的

+1

謝謝你很多相對路徑!這工作。再次讓我頭痛:-) –

+0

不客氣Posix的路徑是好的,如果你想運行shell命令 – mcgrailm

+0

此外,是否有可能重命名文件到某個名稱,我必須在彈出的文本框或類似的東西那? –

0

首先在Finder是拷貝文件duplicate

取景器只接受HFS路徑(冒號分隔)

使腳本便攜式它建議使用像path to documents folder

set documentsFolder to path to documents folder as text 

set newName to text returned of (display dialog "Enter a Name" default answer "" buttons {"Cancel", "OK"} default button 2) 

if newName does not end with ".pages" the set newName to newName & ".pages" 

tell application "Finder" 
    set theWin to window 1 
    set thePath to target of theWin as alias 
    set duplicatedFile to duplicate file (documentsFolder & "NieuwBestandSource:Naamloos.pages") to thePath 
    set name of duplicatedFile to newName 
end tell 
+0

謝謝;作品完美無瑕。另外,在複製我的文件之前,您是否知道使用dialoge box爲其指定自定義名稱的方法? –

+0

我更新了答案。 – vadian

+0

非常感謝:-) –

相關問題