【发布时间】:2021-02-17 20:15:35
【问题描述】:
首先,让我强调一下,我几乎没有 Applescript 经验。我是一名 Oracle 开发人员,所以请假设我的知识是零,所以如果你能真正愚蠢地回答,我将不胜感激。
我大约一年前写了这个脚本,但它突然停止工作了。我猜 macOS 升级(在 High Sierra 上)不再容忍我可能写得不好的脚本。
on run {input, parameters}
repeat with theFile in input
set FileName to theFile as text
tell application "Finder"
if FileName ends with "-xs.jpg" then
--label value, 0 is no label, 1 Orange, 2 Red, 6 Geen
set the label index of file FileName to 6
move FileName to folder "Macintosh HD:Users:Karla:Pictures:FTP:basket-[xs]:" with replacing
else if FileName ends with "-sm.jpg" then
set the label index of file FileName to 1
move FileName to folder "Macintosh HD:Users:Karla:Pictures:FTP:thumbnails-[sm]:" with replacing
else if FileName ends with "-lg.jpg" then
set the label index of file FileName to 2
move FileName to folder "Macintosh HD:Users:Karla:Pictures:FTP:main-[lg]:" with replacing
else if FileName ends with "-xlg.jpg" then
set the label index of file FileName to 5
move FileName to folder "Macintosh HD:Users:Karla:Pictures:FTP:large-[xlg]:" with replacing
end if
end tell
end repeat
return input
end run
我得到的错误是“操作“运行 AppleScript”遇到错误:“Finder 出错:无法设置文件”Macintosh HD:Users:Karla:Pictures:1-IMAGES-TO-DO:image1- lg.jpg" 到 2."
如果我注释掉标记并尝试只是移动,我得到“操作“运行 AppleScript”遇到错误:“Finder 出错:无法获取文件夹”Mackintosh HD:Users:Karla:Pictures :FTP:main-[lg]:"."
编辑:
我也试过了:
on run {input, parameters}
repeat with the_input_file in input
set FileName to POSIX file (the_input_file as alias)
end repeat
return input
end run
但出现错误“运行 AppleScript”操作遇到错误:“无法获取 POSIX 文件(别名“Macintosh HD:Users:Karla:Pictures:file.jpg”)。”
再次编辑:
所以这就是我所在的地方。我创建了一个液滴如下:
on open theDroppedItems
set lg_folder to POSIX path of "Macintosh HD:Users:Karla:Pictures:test1:"
repeat with current_item_cnt from 1 to count of theDroppedItems
-- load the next file in the_file
set the_current_file to item current_item_cnt of theDroppedItems
move file the_current_file to lg_folder
end repeat
end open
我仍然在文件上收到 -1728 错误。 “无法获取文件(别名 \"Macintosh HD:Users:Karla:Pictures:test1:test-lg.jpg\")。”来自文件的编号 -1728(别名“Macintosh HD:Users:Karla:Pictures:test1:test-lg.jpg”)
我花了 2 天时间编写一个曾经可以工作的脚本,但现在却莫名其妙地无法完成我真正的工作。这应该让我的生活更轻松。
【问题讨论】:
-
输出文件路径
-
您尝试过使用 Posix 路径而不是 hfs 吗? "/Users/Karla/..." 而不是 "Macintosh HD:Users:Karla:..." 将 hfs 转换为 posix 使用 "posix path of someHFSPath"
-
是的。也许如果有人可以解释为什么我的脚本不再有效,我会知道从哪里开始寻找。我不是唯一一个遇到这个问题的人:stackoverflow.com/questions/6250691/…
标签: macos applescript macos-high-sierra