Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't understand a error that happen when assigning variable in applescript

Tags:

applescript

I'm new to applescript and even this community, so this question seems to odd. If so,I'm sorry. But I can't find answers in googling. So let me ask.

When I ran the code

tell application "Evernote"
    set theNote to item 1 of selection
    set theTitle to (title of theNote)
end tell

I got an error that says

/var/folders/fm/k76y42cs1y98bjwfyf951q1r0000gn/T/vbkvTSQ/55:47:53: execution error: Evernote got an error: Can’t make item 1 of selection into type specifier. (-1700)

but if I run below,

tell application "Evernote"
    set theNote to (selection)
    set theNote to item 1 of theNote
    set theTitle to (title of theNote)
end tell

I could get expected result.

Why does this error happen? I can't see the deffernce of two codes.

like image 981
user3394926 Avatar asked Mar 13 '14 09:03

user3394926


1 Answers

Applescript's implied get strikes again!!

Try doing this instead:

tell application "Evernote"
    set theNote to item 1 of (get selection)
    set theTitle to (title of theNote)
end tell

Applescript is well meaning, but it hides a lot of implementation details, which makes some errors seem more random than they are. The pitfalls of the "implied get command" have been covered pretty well already, so I'll just summarize with a quote.

One thing that can cause problems is the command "get". In general when you run a command like "name of me" the command get is implied so you're really running "get name of me". The problem is that the implied "get" is not always the case. So sometimes you have to explicitly say "get". Whenever I have a problem like yours the first thing I try is to add "get" to the command...

like image 188
Darrick Herwehe Avatar answered Sep 21 '22 03:09

Darrick Herwehe