I trying to output a list of todo items from the Mac app Things using AppleScript.
But I get a syntax error:
Expected expression but found “to”.
Since Things uses the name “to dos” and AppleScript doesn’t like this, since to is a reserved keyword. It works without a problem if the repeat code is directly inside the tell statement and not in the function handler.
Is there any way around this?
set output to ""
on getTodos(listName)
repeat with todo in to dos of list listName
set todoName to the name of todo
set output to output & todoName
end repeat
end getTodos
tell application "Things"
getTodos("Inbox")
getTodos("Today")
end tell
Is this even possible to do it like this?
And is there a better way to do this?
Sure, this is readily doable. The problem is that outside the
tell application "Things" ... end tellblock, AppleScript doesn’t know what things would be special inside it, and doesn’t even both to look. All you need to do, then, is move thetellblock withinon getTodos(listName) ... end getTodos:You may also be able to replace
tellwithusing terms from; I think that should work. Also, you never uselistName—did you mean to replace"Inbox"withlistName?You should, however, be able to replace
getTodoswith the single lineThis sort of shortcut is one of the things AppleScript is good at. Also, note that this new version doesn’t modify
output, but just returns the list; I’d argue that’s a better decision anyway, but you can always doset output to output & ....