我正在编写AppleScript
编程,允许我自动为文件添加前缀,并在将其复制到特定文件夹时将其上传到ftp服务器(用作OS X El Capitan下的文件夹操作) )。
我开始工作的是文件是自动上传的,但是当我尝试实现它应该添加一个前缀(特别是一个unix时间戳)时,它不会改变文件名也不会将其上传到ftp- 。目录
这是我现在的代码:
property uploadftp : "ftp://user:password«ftpxyz.de/directory/" --this will be changed to the real one
set nowSeconds to ((current date) - (date ("1/1/1970")) - (time to GMT)) as miles as string
set timestamp to nowSeconds & "_"
set Tag to timestamp
on adding folder items to this_folder after receiving added_items
set thelist to ""
repeat with i in added_items
set thelist to thelist & return & i & ","
try
set theFiles to thelist
repeat with aFile in theFiles
set name of aFile to Tag & name of aFile
end repeat
do shell script "curl -T " & quoted form of POSIX path of i & space & quoted form of uploadftp
on error e number n
display dialog "Error: " & e & "Number: " & n
end try
end repeat
display dialog "Dateien empfangen: " & (count added_items) & return & "Ordner: " & POSIX path of this_folder & return & "Dateien: " & thelist
end adding folder items to
答案 0 :(得分:0)
我怀疑剧本是否有效。
主要问题是事件处理程序之外的代码不会在运行时执行。
试试这个:
property uploadftp : "ftp://user:password«ftpxyz.de/directory/" --this will be changed to the real one
on adding folder items to this_folder after receiving added_items
set timestamp to ((current date) - (date ("1/1/1970")) - (time to GMT)) as miles as string
set thelist to {}
repeat with aFile in added_items
try
set fileName to name of (info for aFile)
set newFileName to timestamp & "_" & fileName
set end of thelist to fileName
do shell script "curl -T " & quoted form of POSIX path of aFile & space & quoted form of (uploadftp & newFileName)
on error e number n
display dialog "Error: " & e & "Number: " & n
end try
end repeat
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set receivedFiles to thelist as text
set AppleScript's text item delimiters to saveTID
display dialog "Dateien empfangen: " & (count added_items) & return & "Ordner: " & POSIX path of this_folder & return & "Dateien: " & receivedFiles
end adding folder items to