我正在尝试修改一个带有文本文件的applescript,并使用文本文件的每一行创建一个新的待办事项:
set myFile to (choose file with prompt "Select a file to read:")
open for access myFile
set fileContents to read myFile using delimiter {linefeed}
close access myFile
tell application "Things"
repeat with currentLine in reverse of fileContents
set newToDo to make new to do ¬
with properties {name:currentLine} ¬
at beginning of list "Next"
-- perform some other operations using newToDo
end repeat
end tell
相反,我希望能够简单地将剪贴板用作数据源,这样我就不必每次都创建和保存文本文件,有没有办法加载剪贴板,并且对于每个换行符,执行newToDo 功能?
到目前为止,这是我的尝试,但它似乎不起作用并将整个剪贴板放在一行中,我似乎找不到合适的分隔符。
try
set oldDelims to AppleScript's text item delimiters -- save their current state
set AppleScript's text item delimiters to {linefeed} -- declare new delimiters
set listContents to get the clipboard
set delimitedList to every text item of listContents
tell application "Things"
repeat with currentTodo in delimitedList
set newToDo to make new to do ¬
with properties {name:currentTodo} ¬
at beginning of list "Next"
-- perform some other operations using newToDo
end repeat
end tell
set AppleScript's text item delimiters to oldDelims -- restore them
on error
set AppleScript's text item delimiters to oldDelims -- restore them in case something went wrong
end try
编辑:在下面的答案的帮助下,代码非常简单!
set listContents to get the clipboard
set delimitedList to paragraphs of listContents
tell application "Things"
repeat with currentTodo in delimitedList
set newToDo to make new to do ¬
with properties {name:currentTodo} ¬
at beginning of list "Next"
-- perform some other operations using newToDo
end repeat
end tell