需要了解我的自定义AppleScript吗

需要了解我的自定义AppleScript吗,applescript,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.pa

我最近开始摆弄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  
显然这不是我想要达到的。我只是不知道如何将文件复制到路径。有人能帮我吗


干杯

这是因为您试图使用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

end tell

首先,在查找程序中复制文件的正确命令是
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   

多谢各位!这起作用了。让我省去了另一个头疼的事:-)不用客气如果你试图运行shell命令,Posix路径是好的,是否可以将文件重命名为我必须在弹出文本框或类似文本框中指定的某个名称?是的,您需要将显示对话框返回的文本转换为变量,并将tac设置为路径末尾。我用它将我的自定义字符串设置为变量。如何将其应用于要复制的文件?将名称设置为返回的文本(显示对话框“指定文件名”默认答案“”),我也不想扩展。要删除的页面谢谢;工作完美无瑕。另外,您知道在复制我的文件之前使用对话框为其指定自定义名称的方法吗?还有一件事:在复制文件之前是否可以更改文件名?因为如果我要复制到的文件夹中有naamloos.pages文件,则该过程会中断,脚本将无法工作。如果要覆盖现有文件,请在
复制
行的末尾添加
,并替换
。无法在复制之前重命名文件。