1

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?

0

2 Answers 2

4

Sure, this is readily doable. The problem is that outside the tell application "Things" ... end tell block, 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 the tell block within on getTodos(listName) ... end getTodos:

on getTodos(listName)
  tell application "Things"
    repeat with todo in to dos of list "Inbox"
      set todoName to the name of todo
      set output to output & todoName
    end repeat
  end tell
end getTodos

You may also be able to replace tell with using terms from; I think that should work. Also, you never use listName—did you mean to replace "Inbox" with listName?

You should, however, be able to replace getTodos with the single line

on getTodos(listName)
  tell application "Things" to get the name of the to dos of list listName
end getTodos

This 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 do set output to output & ....

Sign up to request clarification or add additional context in comments.

Comments

0

I believe the issue is that AppleScript does not know you are trying to use Things-specific terminology in your handler. Try putting the repeat within a using terms from application Things block, like so:

on getTodos(listName)
    using terms from application "Things"
        repeat with todo in to dos of list "Inbox"
            set todoName to the name of todo
                    set output to output & todoName
        end repeat
    end using terms from
end getTodos

1 Comment

This works, but I think putting it into a tell block makes for cleaner code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.