テキスト ファイルを受け取り、テキスト ファイルの各行で新しい todo を作成する 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
代わりに、代わりにクリップボードをデータ ソースとして単純に使用できるようにしたいので、毎回テキスト ファイルを作成して保存する必要はありません。クリップボードをロードする方法はありますか。改行ごとに、新しいToDo機能?
これはこれまでの私の試みですが、うまくいかないようで、クリップボード全体を 1 行にまとめてしまいます。適切な区切り文字が見つからないようです。
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