Help us understand the problem. What is going on with this article?

AppleScriptでEvernoteの子タグを取得するときのコツ

More than 3 years have passed since last update.
  • Evernoteのタグは階層構造をとれる
    • 例:とある4つのタグが次のような構造になっているとする
  • ParentTag
    • ChildTag1
    • ChildTag2
    • ChildTag3
  • AppleScriptからもタグの親子関係を取得可能
    • タグのparent属性を使う

tag n : A tag.

elements
contained by application.

properties
name (text) : The tag's name.
parent (tag or missing value) : The tag's parent tag, if any.

responds to
assign, unassign.

  • しかし子タグを取得するのがとても遅い
    • 次の単純なAppleScriptで30秒以上もかかってしまう
tell application "Evernote"
    set parentTag to tag "ParentTag"

    set timestamp to current date --start

    get tags whose parent = parentTag
    --> {tag "ChildTag2", tag "ChildTag3", tag "ChildTag1"}

end tell
log "time: " & (current date) - timestamp & " seconds" --end
(*time: 31 seconds*)
  • 子タグをスムーズに取得するコツ
    • フィルタの比較項目を変える
      • get tags whose ...の行だけ違う
      • 上のAppleScriptは タグそのものでフィルタ をかけていた
      • 下のAppleScriptは タグの名前でフィルタ をかけている
    • 動作時間は31秒から0秒に短縮
      • 一見回りくどいことをやっているけれど名前でフィルタをかけた方が高速
tell application "Evernote"
    set parentTag to tag "ParentTag"

    set timestamp to current date --start

    get tags whose name of parent = (name of parentTag as text)
    --> {tag "ChildTag2", tag "ChildTag3", tag "ChildTag1"}

end tell
log "time: " & (current date) - timestamp & " seconds" --end
(*time: 0 seconds*)
  • おまけ:最上階層のタグのみを取得する方法
    • タグの名前でフィルタする必要はない
tell application "Evernote"
    get tags whose parent = missing value
end tell
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした