1. Evernoteの位置情報を使う(7) - withEverで現在地のノートを検索する

    Evernoteに位置情報つきノートが増えてきました。

    貯めたノートの位置情報を使う一つの方法として、現在地のノートを表示してみます。

    「現在地」でEvernoteを串刺し検索する「AroundEver」

    今回作成した「AroundEver」は、実行すると、iPhoneのGPSを使って位置情報を取得し、現在地周辺のノートをwithEverで検索します。

    「AroundEver」を使えば、Evernote Foodの記録を見て「この店に来るのは半年ぶり」なんてことがわかるし、Evernote Helloの記録を見て「半年前は友達と一緒に来た」ことも簡単にわかります。

    手軽に「現在地」でEvernoteを串刺し検索する「AroundEver」、ぜひ使ってみてください。

    MyScriptsを使うスクリプト版ブラウザからアクセスするHTML版を作成しました。環境に合わせて好きな方をどうぞ。

    MyScripts版導入

    以下のリンクをタップして、スクリプトを登録します。

    AroundEver

    登録したら、実行形式のリンクをコピーします。

    [四角+矢印]>「リンクを作成…」>「スクリプト実行用(クリップボード)」を選択。

    実行用URLがコピーされるので、起動しやすい方法で登録して使います。

    Touch Icon Creatorでホーム画面に置いてもいいし、URLスキームを使えるランチャーアプリに登録してもいいです。

    HTML版導入

    以下のリンクを長押しして、コピーします。

    AroundEver

    MyScripts版と同様に、Touch Icon Creatorやランチャーアプリに登録して使いましょう。

    AroundEverの使い方

    実行すると、位置情報の利用を訊ねるポップアップが表示されます。

    「OK」を選択。

    すぐにwithEverが立ち上がり、Evernoteを検索します。

    現在地周辺のノートが表示されました。

    2回目以降は、位置情報利用を確認するポップアップが表示されないため、一発で検索することができます。

    おわりに

    現在地以外の特定の場所を検索する場合は、この記事にあるブックマークレットが便利です。Google Mapで表示した範囲に含まれるノートを検索することができます。

    Evernoteの位置情報を使う(2) - 地図から検索する - s_z_k_3’s Scripts in Tumblr.com

    withEver App
    カテゴリ: 仕事効率化
    価格: ¥85

    MyScripts App
    カテゴリ: 仕事効率化
    価格: ¥350

    Touch Icon Creator App
    カテゴリ: ユーティリティ
    価格: ¥85

    Launch+ App
    カテゴリ: 仕事効率化
    価格: ¥170

    Launch Center - 等のアプリのタスクをスケジュールします App
    カテゴリ: 仕事効率化
    価格: ¥85

    ソースコード

    
    //withEverで現在地周辺のノートを検索
    //by @s_z_k_3
    navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
    
    function successCallback(position) {
        var earthRad = 6378150;
        var lat = position.coords.latitude;
        var lng = position.coords.longitude;
        var latRange = 500 * 360 / (2 * Math.PI * earthRad);
        var lngRange = 500 * 360 / (earthRad * (Math.cos(lat / 180 * Math.PI)) * 2 * Math.PI);
        var query = "latitude:"+(lat - latRange)+" -latitude:"+(lat + latRange)+" longitude:"+(lng - lngRange)+" -longitude:"+(lng + lngRange);
        window.location = "withever://search?"+encodeURIComponent(query);
    }
    
    function errorCallback(error) {
        var err_msg = "";
        switch(error.code)
        {
            case 1:
                err_msg = "位置情報の利用が許可されていません";
                break;
            case 2:
                err_msg = "デバイスの位置が判定できません";
                break;
            case 3:
                err_msg = "タイムアウトしました";
                break;
        }
        alert(err_msg);
    }
    
    

    Evernoteの位置情報を使う

  2. iOS Apps Updater - iTunesからiOSアプリを一括アップデートするAppleScript

    iOSアプリは数が多く、たくさんダウンロードすると、その分アプリのアップデートも多くなります。

    人によってアプリのアップデートを確認する頻度は違うと思いますが、いずれにせよ繰り返し確認しなければなりません。この作業を自動化してしまいましょう。

    iOS Apps Updater.app 導入

    下のリンクからアプリケーションをダウンロードします。

    iOS Apps Updater.app.zip

    「システム環境設定.app」から「ユニバーサルアクセス」>「補助装置にアクセスできるようにする」をチェック。

    設定は以上です。

    「iOS Apps Updater.app」を実行すると、「iTunes.app」でiOSアプリを自動でアップデートします。

    自動実行の設定

    iOSデバイスをMacに接続したタイミングで「iOS Apps Updater.app」を自動実行するように設定します。

    まずは、iTunesの自動同期を無効にします。

    「iTunes.app」を起動。「環境設定…」から「デバイス」>「iPod、iPhone、および iPad を自動的に同期しない」にチェックを入れます。

    「OK」を選択。

    次に、MacにiOSデバイスを接続したタイミングで「iOS Apps Updater.app」を起動する設定をします。

    iOSデバイスをMacにつなぎ、アプリケーションフォルダにある「イメージキャプチャ.app」を起動。

    サイドバーの「デバイス」からiOSデバイスを選択。左下の「▲」をクリックしてデバイス設定を表示します。

    「この iPhone を接続時に開くアプリケーション」>「その他…」から「iOS Apps Updater.app」を選択。

    「読み込み後に削除」のチェックを外す誤ってここをチェックすると、カメラロールの画像が勝手に削除されてしまいます

    「イメージキャプチャ.app」を終了します。

    自動実行の設定は完了です。これでiOSデバイスをMacに接続すると自動で「iOS Apps Updater.app」が起動します。

    MacにつなぐiOSデバイスが複数ある場合は、すべての端末で同じく設定しましょう。

    注意事項

    「イメージキャプチャ.app」は画像を転送するアプリケーションなので、接続デバイスに画像がないと実行できません。したがって、iOSデバイスのカメラロールに画像がない場合は、Macに接続しても「iOS Apps Updater.app」は自動実行されません。この点だけ注意してください。

    ダウンロード

    iOS Apps Updater.app.zip

    ソースコード

    —前面にあるアプリケーション取得
    set curApplication to path to frontmost application as text
    try

    —iTunes起動
    activate application “iTunes”
    tell application “System Events”

    —画面遷移待ち
    repeat until exists process “iTunes“‘s window “iTunes“‘s scroll area
    end repeat

    —ライブラリの「App」選択
    tell (process “iTunes“‘s window “iTunes“‘s scroll areawhose description = “ソース”)’s item 1’s outline 1
    set curSource to rowwhose selected = true
    select (rowwhose static text 1’s name starts with “App”)
    end tell

    —画面遷移待ち
    repeat until exists process “iTunes“‘s window “iTunes“‘s button “さらに App を入手”
    end repeat

    —アップデートを確認
    keystroke “r” using command down

    —画面遷移待ち
    try
    repeat until ((process “iTunes“‘s window 1’s scroll areawhose description = “ソース”)’s item 1’s outline 1’s rowwhose selected = true)’s static text 1’s value = “iTunes Store”
    end repeat

    —アップデート
    perform (process “iTunes“‘s window “iTunes“‘s UI element “iTunes Store“‘s UI elementwhose role = “AXLink”)’s action 1

    —アップデート待ち
    repeat until exists ((process “iTunes“‘s window “iTunes“‘s scroll areawhose description = “ソース”)’s item 1’s outline 1’s rows whose static text 1’s value starts with “ダウンロード”)

    —年齢認証ダイアログ
    if exists (process “iTunes“‘s windows whose subrole = “AXDialog”) then
    click process “iTunes“‘s window 1’s button “OK”
    end if
    end repeat
    set downloadSource to (process “iTunes“‘s window “iTunes“‘s scroll areawhose description = “ソース”)’s item 1’s outline 1’s rowwhose static text 1’s value starts with “ダウンロード”
    repeat while downloadSource’s static text 1’s value ends with “ダウンロード中”
    delay 1
    end repeat
    on error

    —アップデートなし
    if process “iTunes“‘s window 1’s subrole = “AXDialog” then
    click process “iTunes“‘s window 1’s button “OK”
    end if
    end try

    —ライブラリの選択項目を戻す
    select curSource
    end tell

    —前面アプリケーションを戻す
    activate application curApplication

    —iOSデバイス同期
    tell application “iTunes”
    set devices to sources whose kind = iPod
    repeat with aDevice in devices
    update aDevice
    end repeat
    end tell
    end try

  3. Chromeで右クリックからリンクを「ブックマークに追加」するAutomatorサービス

    動作の軽さが売りのGoogle製ブラウザアプリ「Google Chrome」。メインブラウザとして使っています。

    なかなか手に馴染んでいますが、ちょっとした不便を感じるところがいくつか…

    右クリックから「ブックマークに追加」できると便利

    MacBookを使っているのですが、少しでもタテに余裕を持たせるため、Chromeのブックマークバーを非表示にしています。そのため、表示しているページに含まれるリンクをブックマークに追加するのは少し面倒です。

    そこで、ページ内のリンクを右クリックしてブックマークに追加するAutomatorサービスを作成しました。

    ChromeBookmark導入

    下のリンクから「ChromeBookmark.worklow.zip」をダウンロードします。

    追記:ブックマーク名がエンコードされたまま登録される不具合を修正しました。(2012-05-16)

    リンク:ChromeBookmark.worklow.zip

    ダウンロードしたファイルを解凍し、ダブルクリックすると「サービス インストーラ」ダイアログが表示されます。

    [インストール]を選択すればインストール完了です。

    ChromeBookmarkを使う

    適当なページでリンクを右クリックし、コンテキストメニュー内の「ChromeBookmark」を選択。

    表示されるダイアログで「ブックマークを追加するフォルダ」を選択します。

    たったこれだけでブックマークに追加されました。便利!

    注意:フォルダ内に登録するブックマークと同一名のブックマークがある場合、きちんと動作しない場合があります。

    さらにChromeBookmarkを使う

    選択範囲を広げてみましょう。複数のリンクが含まれるようにします。

    同様に右クリックのコンテキストメニューから「ChromeBookmark」を実行。

    選択範囲に含まれるリンクがすべてブックマークに追加されました。すごい便利!

    これがあれば、「ブックマークレットまとめページ」などで非常に捗るでしょう。

    Chromeユーザはぜひ使ってみてください。

    ブログ更新を快適に!ブロガー必須のブックマークレット まとめ | nori510.com
    iphoneで必須のbookmarklet まとめ[ブックマークレット] | nori510.com
    【特選】激しく使える便利なブックマークレットまとめ - NAVER まとめ
    iPhone/iPadで使えるブックマークレットまとめ - NAVER まとめ
    JAVASCRIPT::BOOKMARKLET
    Google Chrome おすすめ ブックマークレット まとめ
    ブックマークレットまとめ Harmonia!!

    ダウンロード

    ChromeBookmark.worklow.zip

    ソースコード

    (workflow内「AppleScript を実行」部分)
    on run {input, parameters}

    (* Your script goes here *)
    my registerNotificationsOnGrowl(“ChromeBookmark”, {“Finish”, “Error”}, {“Finish”, “Error”}, “Google Chrome”)
    try
    set linkList to my getLinkListFromSelection()
    my addBookmarkInChrome(linkList)
    on error errorMessage
    my growlNotify(“Error”, “Error in ChromeBookmark”, errorMessage, “ChromeBookmark”, true)
    end try

    return
    end run

    on registerNotificationsOnGrowl(applicationName, allNotifications, defaultNotifications, iconApplicationName)
    アイコンを設定しない場合:iconApplicationName = missing value
    tell application id “com.Growl.GrowlHelperApp”
    if iconApplicationName = missing value then
    register as application applicationName all notifications allNotifications default notifications defaultNotifications
    else
    register as application applicationName all notifications allNotifications default notifications defaultNotifications icon of application iconApplicationName
    end if
    end tell
    end registerNotificationsOnGrowl

    on getLinkListFromSelection()
    set oldClipboard to the clipboard as record
    set the clipboard to “”
    repeat with i fromto 30
    tell application “Google Chrome”
    tell active tab of front window
    copy selection
    end tell
    end tell
    try
    set rawData to the clipboard as «class HTML»
    exit repeat
    end try
    if i ≥ 30 then
    errorリンクが選択されていません
    end if
    end repeat
    set the clipboard to oldClipboard
    try
    rawData as Unicode text
    on error errorMessage
    —set rawDataText to my replace(errorMessage, ” のタイプを Unicode text に変換できません。”, “”)
    —set hexData to text 11 thru -2 of rawDataText
    set hexData to textthru -2 of itemof my split(errorMessage, space)
    end try
    set aHTML to do shell script “echo ” & quoted form of hexData & ” | xxd -r -p”

    set aList to my split(aHTML, “<a “)
    if (count aList) < 2 then
    errorリンクが選択されていません
    end if
    set linkList to {}
    repeat with aItem in rest of aList
    set aLink to my pickUpFromText(“<a ” & aItem, “<a “, “</a>”)
    set aTitle to my xmldecode(my removeBracketed(aLink, “<”, “>”))
    set aURL to my xmldecode(textthru -2 of itemof my split(itemof my split(aLink, “href=”), {space, “>”}))
    set end of linkList to {aTitle, aURL}
    end repeat
    return linkList
    end getLinkListFromSelection

    on addBookmarkInChrome(linkList)
    tell application “Google Chrome”
    activate
    set bookmarkFolderList to my indentBookmarkFolder()
    set chooseBookmarkFolderNameResult to choose from list bookmarkFolderList
    if chooseBookmarkFolderNameResult = false then
    error number -128
    end if
    set selectedBookmarkFolderName to itemof chooseBookmarkFolderNameResult
    set bookmarkFolderIndex to my indexInList(bookmarkFolderList, selectedBookmarkFolderName, return)
    set aBookmarkFolderName to my trimCharFromText(selectedBookmarkFolderName, space)
    set aBookmarkFolder to my searchBookmarkFolder(aBookmarkFolderName)
    —make new bookmark item at aBookmarkFolder with properties {title:aTitle, URL:aURL}
    end tell

    repeat with aLink in linkList
    set {aTitle, aURL} to aLink
    tell application “System Events”
    keystroke “d” using command down
    tell process “Google Chrome”
    repeat until exists window 1’s button完了
    end repeat
    set window 1’s group 1’s text field 1’s value to aTitle
    tell window 1’s group 1’s pop up button 1
    if valueaBookmarkFolderName then
    perform action “AXShowMenu”
    delay 0.5
    repeat bookmarkFolderIndex times
    key code 125
    delay 0.2
    end repeat
    keystroke return
    end if
    end tell
    perform window 1’s button完了“‘s action “AXPress”
    end tell
    end tell
    tell application “Google Chrome”
    set URL of bookmark item aTitle of aBookmarkFolder to aURL
    end tell
    my growlNotify(“Finish”, “Added to Bookmark”, quoted form of aTitle & ” をブックマークに追加しました”, “ChromeBookmark”, false)
    delay 1
    end repeat
    end addBookmarkInChrome

    on growlNotify(notificationName, titleText, descriptionText, applicationName, stickyBoolean)
    tell application id “com.Growl.GrowlHelperApp”
    notify with name notificationName title titleText description descriptionText application name applicationName sticky stickyBoolean
    end tell
    end growlNotify

    on replace(str, find, replace)
    set {str, replace} to {str as text, replace as text}
    set oldDel to AppleScript’s text item delimiters
    try
    set AppleScript’s text item delimiters to find
    set replaceList to every text item of str
    set AppleScript’s text item delimiters to replace
    set str to replaceList as string
    on error errorMessage
    set AppleScript’s text item delimiters to oldDel
    error errorMessage
    end try
    set AppleScript’s text item delimiters to oldDel
    return str
    end replace

    on split(str, delim)
    set str to str as text
    set oldDel to AppleScript’s text item delimiters
    try
    set AppleScript’s text item delimiters to delim
    set aList to text items of str
    on error errorMessage
    set AppleScript’s text item delimiters to oldDel
    error errorMessage
    end try
    set AppleScript’s text item delimiters to oldDel
    return aList
    end split

    on pickUpFromText(theText, beginStr, endStr)
    —theTextの内、beginStrからendStrまでを返す
    存在しない場合はエラー
    set aList to my split(theText, beginStr)
    set bList to itemsthru -1 of aList
    set c to my join(bList, beginStr)
    set dList to my split(c, endStr)
    set eList to itemsthru -2 of dList
    set f to my join(eList, endStr)
    return beginStr & f & endStr
    end pickUpFromText

    on removeBracketed(aText, aBracket, bBracket)
    set aList to my split(aText, aBracket)
    repeat with i fromto count aList
    set aItem to item i of aList
    set startPoint to offset of bBracket in aItem
    if startPoint = 0 then
    set bItem to aItem
    else if startPoint = length of aItem then
    set bItem to “”
    else
    set bItem to text (startPoint + 1) thru -1 of aItem
    end if
    set item i of aList to bItem
    end repeat
    return aList as text
    end removeBracketed

    on xmldecode(param)
    set aClass to class of param
    if aClass is list then
    set itemList to param
    repeat with i fromto count itemList
    set anItem to item i of itemList
    set anItem to my xmldecode(anItem)
    set item i of itemList to anItem
    end repeat
    return itemList
    else
    set theText to param as text
    set theText to my replace(theText, “&quot;”, quote)
    set theText to my replace(theText, “&lt;”, “<”)
    set theText to my replace(theText, “&gt;”, “>”)
    set theText to my replace(theText, “&apos;”, “’”)
    set theText to my replace(theText, “&amp;”, “&”)
    return theText
    end if
    end xmldecode

    on indentBookmarkFolder()
    set bookmarkFolderList to {}
    tell application “Google Chrome”
    set bookmarkFolderList to my indentBookmarkFolderSubroutine(bookmarkFolderList, bookmarks bar, “”)
    set bookmarkFolderList to my indentBookmarkFolderSubroutine(bookmarkFolderList, other bookmarks, “”)
    end tell
    return bookmarkFolderList
    end indentBookmarkFolder

    on indexInList(aList, getItem, delim)
    if contents of aList = {} then
    return 0
    else if getItem = first item of aList then
    return 1
    else if getItem = last item of aList then
    return count aList
    else
    my join(aList, delim)
    my split(result, delim & getItem & delim)
    my split(itemof result, delim)
    set aIndex to count result
    if aIndex = (count aList) then
    return 0
    else
    return aIndex + 1
    end if
    end if
    end indexInList

    on trimCharFromText(theText, deleteChar)
    1引数の先頭と末尾からdeleteCharを取り除く
    ignoring white space
    if contents of theText = “” then
    return “”
    else
    set i to 1
    repeat while character i of theText is deleteChar
    set i to i + 1
    end repeat
    set j to -1
    repeat while character j of theText is deleteChar
    set j to j - 1
    end repeat
    return text i thru j of theText
    end if
    end ignoring
    end trimCharFromText

    on searchBookmarkFolder(theBookmarkFolderName)
    tell application “Google Chrome”
    if exists bookmark folder theBookmarkFolderName then
    return bookmark folder theBookmarkFolderName
    end if
    repeat with aBookmarkFolder in bookmark folders
    set returnBookmarkFolder to my searchBookmarkFolderSubroutine(theBookmarkFolderName, aBookmarkFolder)
    if returnBookmarkFolderfalse then
    return returnBookmarkFolder
    end if
    end repeat
    end tell
    return false
    end searchBookmarkFolder

    on join(textList, term)
    set term to term as text
    set oldDel to AppleScript’s text item delimiters
    try
    set AppleScript’s text item delimiters to term
    set aText to textList as string
    on error errorMessage
    set AppleScript’s text item delimiters to oldDel
    error errorMessage
    end try
    set AppleScript’s text item delimiters to oldDel
    return aText
    end join

    on indentBookmarkFolderSubroutine(bookmarkFolderList, theBookmarkFolder, prefix)
    tell application “Google Chrome”
    tell theBookmarkFolder
    set end of bookmarkFolderList to prefix & title
    repeat with aBookmarkFolder in my sortBookmarkFolders(bookmark folders)
    set bookmarkFolderList to my indentBookmarkFolderSubroutine(bookmarkFolderList, aBookmarkFolder, space & space & space & space & prefix)
    end repeat
    end tell
    end tell
    return bookmarkFolderList
    end indentBookmarkFolderSubroutine

    on searchBookmarkFolderSubroutine(theBookmarkFolderName, theBookmarkFolder)
    tell application “Google Chrome”
    tell theBookmarkFolder
    if exists bookmark folder theBookmarkFolderName then
    return bookmark folder theBookmarkFolderName
    end if
    repeat with aBookmarkFolder in bookmark folders
    set returnBookmarkFolder to my searchBookmarkFolderSubroutine(theBookmarkFolderName, aBookmarkFolder)
    if returnBookmarkFolderfalse then
    return returnBookmarkFolder
    end if
    end repeat
    end tell
    end tell
    return false
    end searchBookmarkFolderSubroutine

    on sortBookmarkFolders(bookmarkFolderList)
    tell application “Google Chrome”
    set aList to {}
    repeat with aBookmarkFolder in bookmarkFolderList
    tell aBookmarkFolder
    set end of aList to {contents, title}
    end tell
    end repeat
    end tell
    set bList to my shellSortListAscending(aList, 2)
    set cList to {}
    repeat with bItem in bList
    set end of cList to itemof bItem
    end repeat
    return cList
    end sortBookmarkFolders

    on shellSortListAscending(a, keyItem)
    set n to length of a
    set cols to {1391376, 463792, 198768, 86961, 33936, 13776, 4592, 1968, 861, 336, 112, 48, 21, 7, 3, 1}
    repeat with h in cols
    if (h ≤ (n - 1)) then
    repeat with i from h to (n - 1)
    set v to item (i + 1) of a
    set j to i
    repeat while (jh) and ((contents of item keyItem of item (j - h + 1) of a) > (item keyItem of v))
    set (item (j + 1) of a) to (item (j - h + 1) of a)
    set j to j - h
    end repeat
    set item (j + 1) of a to v
    end repeat
    end if
    end repeat
    return a
    end shellSortListAscending

  4. 夜フクロウからEvernoteにTweetをクリップするAppleScript

    MacのTwitterクライアントとして定番の「夜フクロウ」。多機能なのに無料というオススメアプリです。

    夜フクロウ App
    カテゴリ: ソーシャルネットワーキング
    価格: 無料

    SOICHAなど、いくつかのTwitterクライアントには、ツイートやタイムラインをEvernoteにクリップする機能があります。

    どれだけ要望があるかわかりませんが、夜フクロウには今のところ「Evernoteへのクリップ機能」はありません。

    夜フクロウからEvernoteにクリップするAppleScript

    「ないなら作ってしまえ」ということで、EvernoteにクリップするAppleScriptを作成しました。

    下のリンクから「YoruFukurou2Evernote.scpt」をダウンロードしてください。

    リンク:YoruFukurou2Evernote.scpt

    夜フクロウでクリップするTweetを表示して「YoruFukurou2Evernote.scpt」を実行すると、Evernoteにクリップされます。

    簡単ですね。

    夜フクロウユーザはぜひ使ってみてください。

    おわりに

    かなり機能を限定して公開しました。

    他にも

    • Evernote取り込み時のノートブック、タグ指定
    • ノートタイトルの変更
    • 取り込むTweetの選択

    ができたりしますが、どうしてもクリップまでの手数が多くなります。なかなか悩ましいです。

    手数を抑える良いアイデア、煩雑になってでもほしい機能がありましたら、ぜひ@s_z_k_3まで教えてください。

    ダウンロード

    YoruFukurou2Evernote.scpt

    ソースコード

    —夜フクロウのTweet取得
    tell application “System Events”
    tell process “YoruFukurou”
    set tweetList to window 1’s scroll area 2’s table 1’s rows’s static texts’s value
    end tell
    end tell

    —Tweet数が多いときの警告
    set countTweets to count tweetList
    if countTweets > 30 then
    tell application “YoruFukurou”
    activate
    display dialog {countTweets & ” ツイートあるため、取り込みに時間がかかります。”, return, “Evernoteへの取り込みをつづけますか?”} as text buttons {“中止”, “つづける”} default button “つづける” cancel button “中止” with title “YoruFukurou2Evernote” with icon 2
    end tell
    end if

    —初期化
    set accountList to {}
    set tableHTMLList to {“<table border=’0’ width=’100%’ cellpadding=’10px’ cellspacing=’0’>
    <tbody>
    ”}

    —Tweet解析
    repeat with tweet in tweetList
    set aList to my split(tweet, ” - “)
    set {userID, userName} to itemsthruof aList
    set {retweet, datetime} to items -2 thru -1 of aList
    if retweet starts with “Retweeted by ” then
    set tweetContent to my join(itemsthru -3 of aList, ” - “)
    set bList to my split(retweet, space)
    set retweetUserID to item -1 of bList
    set last item of bList to “<a href=’https://twitter.com/#!/” & retweetUserID & “’ target=’_blank’>@” & retweetUserID & “</a>”
    set retweet to my join(bList, space)
    else
    set tweetContent to my join(itemsthru -2 of aList, ” - “)
    set retweet to “”
    end if

    —userIDをaccountListへ追加
    if “@” & userID is not in accountList then
    set end of accountList to “@” & userID
    end if

    —tweetContentをHTML対応
    set tweetContent to my xmlencode(tweetContent)
    set tweetContent to my replace(tweetContent, {return, ASCII character 10}, “<br/>”)

    —tweetContent中のユーザ、ハッシュタグをリンクに置き換え
    —thanks: 【正規表現,jQuery,PHP】twitterハッシュタグを抽出する / すたらSample http://www.usamimi.info/~sutara/sample/hashtag_match.php
    set tweetContent to my replaceUsingRegex(tweetContent, “(?:^|[^ー゛゜々ヾヽぁ-ヶ一-龠a-zA-Z0-9a-zA-Z0-9&_\/]+)[##]([ー゛゜々ヾヽぁ-ヶ一-龠a-zA-Z0-9a-zA-Z0-9_]*[ー゛゜々ヾヽぁ-ヶ一-龠a-zA-Z0-9a-zA-Z]+[ー゛゜々ヾヽぁ-ヶ一-龠a-zA-Z0-9a-zA-Z0-9_]*)”, ” <a href=’https:\/\/twitter.com\/#!\/search\/%23$1’ target=’_blank’>#$1<\/a>”)
    set tweetContent to my replaceUsingRegex(tweetContent, “@([0-9a-zA-Z_]{1,15})”, “<a href=’https:\/\/www.twitter.com\/#!\/$1’ target=’_blank’>\@$1<\/a>”)

    —HTML化
    —reference: Twitter Images - http://twitterimag.es http://tweetimag.es/
    set end of tableHTMLList to “<tr style=’background:#f5f5f5;’>
    <td valign=’top’ width=’54px’><a href=’https://twitter.com/#!/” & userID & “’ target=’_blank’><img src=’http://img.tweetimag.es/i/” & userID & “_n’ style=’margin:3px;’/></a></td>
    <td><b>” & userName & ” (<a href=’https://twitter.com/#!/” & userID & “’ target=’_blank’>@” & userID & “</a>)</b><br/>
    ” & tweetContent & “<br/>
    <font color=’#999’>” & retweet & “</font><br/>
    <font color=’#999’>” & datetime & “</font></td>
    </tr>
    end repeat
    set end of tableHTMLList to “</tbody>
    </table>
    set tableHTML to tableHTMLList as text

    —Evernoteでノート作成
    tell application “Evernote”
    set aTitle to “tweets by ” & my join(accountList, “, “)
    set aNote to create note with html tableHTML title aTitle
    set aWindow to open note window with aNote
    activate aWindow
    end tell

    on split(str, delim)
    set str to str as text
    set oldDel to AppleScript’s text item delimiters
    try
    set AppleScript’s text item delimiters to delim
    set aList to text items of str
    on error errorMessage
    set AppleScript’s text item delimiters to oldDel
    error errorMessage
    end try
    set AppleScript’s text item delimiters to oldDel
    return aList
    end split

    on join(textList, term)
    set term to term as text
    set oldDel to AppleScript’s text item delimiters
    try
    set AppleScript’s text item delimiters to term
    set aText to textList as string
    on error errorMessage
    set AppleScript’s text item delimiters to oldDel
    error errorMessage
    end try
    set AppleScript’s text item delimiters to oldDel
    return aText
    end join

    on xmlencode(param)
    set aClass to class of param
    if aClass is list then
    set itemList to param
    repeat with i fromto count itemList
    set anItem to item i of itemList
    set anItem to my xmlencode(anItem)
    set item i of itemList to anItem
    end repeat
    return itemList
    else
    set theText to param as text
    set theText to my replace(theText, “&”, “&amp;”)
    set theText to my replace(theText, quote, “&quot;”)
    set theText to my replace(theText, “<”, “&lt;”)
    set theText to my replace(theText, “>”, “&gt;”)
    set theText to my replace(theText, “’”, “&apos;”)
    return theText
    end if
    end xmlencode

    on replace(str, find, replace)
    set {str, replace} to {str as text, replace as text}
    set oldDel to AppleScript’s text item delimiters
    try
    set AppleScript’s text item delimiters to find
    set replaceList to every text item of str
    set AppleScript’s text item delimiters to replace
    set str to replaceList as string
    on error errorMessage
    set AppleScript’s text item delimiters to oldDel
    error errorMessage
    end try
    set AppleScript’s text item delimiters to oldDel
    return str
    end replace

    on replaceUsingRegex(str, pattern, replace)
    set perlScript to “utf8::decode($_); $_ =~ s/” & pattern & “/” & replace & “/g; print $_;”
    return do shell script “echo ” & quoted form of str & ” | perl -Mutf8 -n -e ” & quoted form of perlScript
    end replaceUsingRegex

  5. ScanSnapからEvernoteに取り込む上で守るべきたった1つのルール

    ScanSnapを日々使っています。レシート、プリント、カードなどなど。

    S1100使ってます。ちっこくてオススメです。

    ScanSnapでスキャンしたファイルはすべてEvernoteに保存します。本の自炊のような大規模なスキャンは行わないので、片っ端からEvernote行きです。

    ScanSnapを使い始めてしばらく経ちますが、過去のスキャンで大きく後悔していることがあるので、そこから得られた教訓を紹介したいと思います。

    タイトルをつける

    いきなり結論を言ってしまうと、Evernoteに取り込む際にノートタイトルを変更したほうがいい、という話です。

    ScanSnapでファイル名をつける方法は、2通りの日付または連番です。

    このままEvernoteに取り込むと、ノートを探すのに苦労します。

    タイトルを日付にするデメリット

    自分はこれまで日付をタイトルにしてEvernoteに取り込んでいました。その経験から言える「ノートタイトルを日付にするデメリット」を挙げてみます。

    前提として、ScanSnapはドキュメントスキャナであるため、書類等をスキャンすることが多いと思います。

    書類ってだいたい白背景に黒字だったりして、パッと見ても内容がわかりにくい。Evernoteにはサマリービュー、サムネールビューがあるけれど、書類をサムネールで判別するのはかなり困難です。

    リストビューだとまず見つかりません。

    ScanSnapやEvernoteにはOCR機能があるため、ノートの絞り込みは意外と簡単にできます。しかし、該当ノートであるかどうかを確かめるのはかなり面倒でした。いちいちそれっぽいノートを選択して、中身を確かめる作業をしなければなりません。

    タイトルをきちんと入力することで、この手間がかなり省けます。実際、ノートタイトルをいちいち入力するようにしてから、目的のノートを見つけるのが早くなりました。

    ということで、ScanSnapからEvernoteに取り込む際は必ずタイトルをきちんとつけるようにしましょう!

    もちろんScanSnapに限らず、他のスキャナやスマートフォンのスキャンアプリを使っている方にも実践してほしいルールです。

    タイトルを毎回つけるのが面倒なあなたへ

    以上を読んで「スキャンするときにノートタイトルを入力しよう!」と決意するのは簡単です。しかし、決意しただけではいずれやらなくなってしまうでしょう。

    現状では、スキャンした後にEvernoteを開いてノートのタイトルを入力しなければいけません。

    わざわざ入力するのは手間がかかるので、「後でまとめて…」などと考えてしまいます。結局、面倒でタイトルをつけなくなってしまうかもしれません。

    こんなときはツールを使いましょう。タイトルを入力しないとScanSnapからEvernoteに取り込めないようにしてしまいます。

    タイトルをつけて、ファイルをEvernoteに取り込むAppleScriptを作成しました。

    以下、ScanSnapでの設定方法を説明していきます。

    下のリンクから「importFilesToEvernote.app.zip」をダウンロードします。

    importFilesToEvernote.app.zip

    解凍してアプリケーションフォルダにでも移動しておきましょう。

    次に「ScanSnap Manager」で設定を行います。

    「ScanSnap Manager.app」を起動し、メニューバーから「設定…」を開きます。[⌘S]でも設定画面を開くことができます。

    「読み取り設定」から「新しい読み取り設定…」を選択。

    すでにある読み取り設定を変更する場合は、該当する読み取り設定を選択します。

    「アプリ選択」タブを開き、「追加と削除…」>「追加…」>「アプリケーションの場所」>「参照…」と進み、ダウンロードした「importFilesToEvernote.app」を選択。

    「アプリケーションの表示名」をわかりやすい名前に設定して「OK」。「アプリケーションの追加と削除」ウインドウの「閉じる」を選択して、「アプリ選択タブ」に戻ります。

    「アプリケーションの選択」で追加したアプリケーション(importFilesToEvernote)を選択します。

    ここまででimportFilesToEvernoteの設定は完了。読み取りモードやファイル形式を自由に設定します。

    設定が完了したら、右下の「適用」を選択して設定を保存します。

    試しにスキャンしてみます。

    Dockの「ScanSnap Manager.app」をクリックし、「読み取り設定」ウインドウで先ほどの読み取り設定を選択。

    ScanSnapで通常通りスキャンします。

    スキャンが完了するとダイアログが表示されます。

    img

    ここにノートタイトルを入力。

    「OK」を選択すると、入力したノートタイトルでEvernoteにノートが作成されます。

    これで必ずノートタイトルを変更する仕組みを作ることができました。

    ノートブック、タグ設定

    「importFilesToEvernote.app」が起動するタイミングで[Shift]を押し続けると、ノートブック、タグ選択ダイアログが表示されます。

    ScanSnapでスキャン完了時に[Shift]を押しながら「Stop」ボタンを押すとうまくいきます。

    一度設定すると、ノートブック、タグの設定は保持されるので初回に設定しましょう。

    スキャン後のファイルを直接ゴミ箱へ

    取り込んだファイルはEvernoteだけでなく、ローカルにも保存されます。

    Evernoteには履歴機能があるため、ローカルファイルは捨ててしまっても良いかもしれません。

    Smart Hacks: ScanSnapとEvernoteの連携が超便利になる裏技をみつけた!

    こちらのページでScanSnapから自動的にゴミ箱に捨てる方法が紹介されています。自分は読んですぐに真似させていただきました。

    おわりに

    「タイトルを変更する必要はないけれど、ノートブックとタグを指定して取り込みたい」という方は以下のリンクからアプリケーションをダウンロードしてください。

    directlyImportFilesToEvernote.app.zip

    設定方法は上と同じです。「ImportFilesToEvernote.app」との違いは、ノートタイトルを入力するダイアログが表示されない点のみです。

    参考ページ

    AS Hole(AppleScriptの穴) By Piyomaru Software » シェルソート高速化比較(さらに改良) » Blog Archive
    AppleScriptであれこれする

    ダウンロード

    importFilesToEvernote.app.zip

    ソースコード

    property ENNotebook : “(既定のノートブック)”
    property ENTags : {}
    property defaultNotebook : “(既定のノートブック)”

    on open dropItems
    repeat with theItem in dropItems
    my importFile(theItem)
    end repeat
    end open

    on run
    set chooseFiles to choose file with multiple selections allowed
    open chooseFiles
    end run

    on importFile(theFile)
    —ノートブック、タグ変更
    set resetSettings to my getModifierKeys() contains “shift”
    if resetSettings then
    set ENNotebook to my chooseNotebook(ENNotebook)
    set tagText to my chooseTags(my join(ENTags, “, “))
    set ENTags to my split(tagText, “, “)
    end if

    —デフォルトのファイル名取得
    tell application “Finder”
    set {name:theName, name extension:theExtension} to (theFile as alias)
    set defaultName to textthru -(2 + (length of theExtension)) of theName
    end tell

    —ノートタイトル入力
    tell application “Evernote”
    activate
    try
    set {text returned:noteTitle} to display dialog “Set note title.” default answer defaultName with icon 1

    —ノート作成
    if ENNotebook = defaultNotebook then
    create note from file theFile title noteTitle notebook (notebookwhose default = true) tags ENTags
    else
    create note from file theFile title noteTitle notebook ENNotebook tags ENTags
    end if
    on error errorMessage number errorNumber
    if errorNumber ≠ -128 then
    display dialog errorMessage buttons {“OK”} default button 1
    end if
    end try
    end tell
    end importFile

    on chooseNotebook(theNotebook)
    tell application “Evernote” to set everyNotebookNameList to my shellSort(name of notebooks)
    set chooseNotebookNameList to {“新規ノートブック作成…”, defaultNotebook} & everyNotebookNameList
    activate
    set chooseNotebookResult to choose from list chooseNotebookNameList with title “ノートブック” default items {theNotebook} with prompt “ノートブックを選択してください:”
    if chooseNotebookResult = false then
    error number -128
    else if chooseNotebookResult = {“新規ノートブック作成…”} then
    set {button returned:notebookType, text returned:notebookName} to display dialog “新規ノートブック名を入力してノートブックタイプを選択して下さい:” default answer “” with title “新規ノートブック作成” buttons {“キャンセル”, “Synchronized”, “Local Only”} default button 1
    run script “tell application "Evernote" to create notebook ” & quote & notebookName & quote & ” with type ” & notebookType
    return notebookName
    else
    return itemof chooseNotebookResult
    end if
    end chooseNotebook

    on chooseTags(theTagText)
    set chooseTagNameList to my returnEveryTagNameList()
    set theTagList to my split(theTagText, “, “)
    activate
    set chooseTagResult to choose from list chooseTagNameList with title “タグ” default items theTagList with prompt “タグを選択してください:” & return & return & “複数選択、選択なしにするには、⌘キーを使って選択状態を変更して下さい。” with multiple selections allowed and empty selection allowed
    if chooseTagResult = false then
    error number -128
    end if
    set newTagText to my join(chooseTagResult, “, “)
    return newTagText
    end chooseTags

    on returnEveryTagNameList()
    tell application “Evernote”
    set everyTagNameList to name of tags
    end tell
    return my shellSort(everyTagNameList)
    end returnEveryTagNameList

    on split(str, delim)
    set str to str as text
    set oldDel to AppleScript’s text item delimiters
    try
    set AppleScript’s text item delimiters to delim
    set aList to text items of str
    on error errorMessage
    set AppleScript’s text item delimiters to oldDel
    error errorMessage
    end try
    set AppleScript’s text item delimiters to oldDel
    return aList
    end split

    on join(textList, term)
    set term to term as text
    set oldDel to AppleScript’s text item delimiters
    try
    set AppleScript’s text item delimiters to term
    set aText to textList as string
    on error errorMessage
    set AppleScript’s text item delimiters to oldDel
    error errorMessage
    end try
    set AppleScript’s text item delimiters to oldDel
    return aText
    end join

    on shellSort(aSortList)
    —thanks: AS Hole(AppleScriptの穴) By Piyomaru Software » シェルソート高速化比較(さらに改良) » Blog Archive http://piyocast.com/as/archives/1982?utm_medium=twitter&utm_source=twitterfeed
    script oBj
    property list : aSortList
    end script
    set len to count oBj’s list’s items
    set gap to 1
    repeat while (gaplen)
    set gap to ((gap * 3) + 1)
    end repeat
    repeat while (gap > 0)
    set gap to (gap div 3)
    if (gap < len) then
    repeat with i from gap to (len - 1)
    set temp to oBj’s list’s item (i + 1)
    set j to i
    repeat while ((jgap) and (oBj’s list’s item (j - gap + 1) > temp))
    set oBj’s list’s item (j + 1) to oBj’s list’s item (j - gap + 1)
    set j to j - gap
    end repeat
    set oBj’s list’s item (j + 1) to temp
    end repeat
    end if
    end repeat
    return oBj’s list
    end shellSort

    on getModifierKeys()
    set theRubyScript to “require ‘osx/cocoa’;
    event=OSX::CGEventCreate(nil);
    mods=OSX::CGEventGetFlags(event);
    print ‘shift ’ if (mods&0x00020000)!=0;
    print ‘control ’ if(mods&0x00040000)!=0;
    print ‘option ’ if(mods & 0x00080000)!=0;
    print ‘command ’ if(mods & 0x00100000)!=0;
    return do shell script “/usr/bin/ruby -e ” & quoted form of theRubyScript
    end getModifierKeys