2014-03-13 22 views
2

我是新來的applescript甚至這個社區,所以這個問題似乎很奇怪。如果是這樣,我很抱歉。 但我無法在Google搜索中找到答案。所以讓我問。無法理解在分配變量時發生的錯誤

當我運行的代碼

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

我,說

/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) 

一個錯誤,但如果我在下面跑,

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

我能得到預期的結果。

爲什麼會發生此錯誤?我看不到兩個代碼的瑕疵。

回答

2

Applescript的隱含get再次罷工!

嘗試這樣做,而不是:

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

AppleScript的是善意的,但它隱藏了許多實施細節,這使得一些錯誤似乎更隨機比他們。 「隱含的獲取命令」have been covered pretty well already的缺陷,所以我只是用引用來總結。

可能導致問題的一件事是命令「get」。一般來說,當你運行一個像「我的名字」這樣的命令時,get命令就是隱含的,所以你真的在運行「獲取我的名字」。問題在於隱含的「獲得」並非總是如此。所以有時你必須明確地說「得到」。每當我遇到像你這樣的問題,我嘗試的第一件事就是在命令中加上「get」...