我想自动将扫描文件(即文件名中带有“-scan”的 pdf 文件)移动到名为“Scan”的文件夹中。 我正在开发一个 AppleScript 代码,该代码可以自动执行将 PDF 文件从“下载”文件夹移动到名为“扫描”的特定文件夹的任务。我要移动的 PDF 文件的名称包含“-scan”。
当我运行脚本时,我收到以下错误消息:
错误“Finder 出现错误:无法获取文件夹“/Users/name/Downloads/”。”文件夹“/Users/name/Downloads/”中的编号 -1728
这是我到目前为止的脚本:
-- Define the path to the download folder
set downloadFolderPath to POSIX path of (path to downloads folder)
-- Define the path to the folder where scanned PDFs will be moved
set scanFolderPath to downloadFolderPath & "Scan/"
-- Get a list of files in the downloads folder
tell application "System Events"
set downloadFiles to name of every file of folder downloadFolderPath
end tell
-- Iterate through the files and move PDFs with "-scan" in their name to the "Scan" folder
repeat with fileName in downloadFiles
if fileName contains "-scan" and fileName ends with ".pdf" then
set filePath to downloadFolderPath & fileName
tell application "Finder"
move file (filePath as POSIX file) to folder scanFolderPath
end tell
end if
end repeat
Finder 不知道 POSIX 路径。如果你继续使用 HFS 路径,你也可以摆脱其他强制舞蹈。
- Define the path to the download folder
set downloadFolderPath to (path to downloads folder as text)
-- Define the path to the folder where scanned PDFs will be moved
set scanFolderPath to downloadFolderPath & "Scan:"
-- Get a list of files in the downloads folder
tell application "System Events"
set downloadFiles to name of every file of folder downloadFolderPath
end tell
-- Iterate through the files and move PDFs with "-scan" in their name to the "Scan" folder
repeat with fileName in downloadFiles
if fileName contains "-scan" and fileName ends with ".pdf" then
set filePath to downloadFolderPath & fileName
tell application "Finder"
move file filePath to folder scanFolderPath
end tell
end if
end repeat
或更短
-- Define the path to the download folder
set downloads to path to downloads folder
tell application "Finder"
move (every file of downloads whose name contains "-scan" and name extension is "pdf") to folder "Scan" of downloads
end tell