LauchBarからGoogle検索するためには
LaunchBarアクティブにする→g→リターン→検索語入力
と、けっこう面倒なのでスクリプトを作った。
tell application "LaunchBar"
activate
delay 0.2
tell application "System Events"
keystroke "g"
delay 0.1
keystroke return
end tell
end tell
delayが無いとLaunchBarがキーストロークを拾いません。
環境によってはdelayの値を変更しないと行けないかも。
これをSparkでCtrl+Shift+Cmd+gにバインド。
LaunchBarからiTunesの再生中の曲にレートをつけるスクリプトを作成。Genius Mixでは利用できないみたい。
tell application "iTunes"
set targetId to database ID of current track
set targetTrack to item 1 of (every track of current playlist whose database ID is targetId)
set ratings to {"・・・・・", "★・・・・", "★★・・・", "★★★・・", "★★★★・", "★★★★★"}
set selectedItem to item 1 of {choose from list ratings}
if selectedItem = false then return
set selectedRating to item 1 of selectedItem
if selectedRating = "・・・・・" then
set ratingNumber to 0
else if selectedRating = "★・・・・" then
set ratingNumber to 20
else if selectedRating = "★★・・・" then
set ratingNumber to 40
else if selectedRating = "★★★・・" then
set ratingNumber to 60
else if selectedRating = "★★★★・" then
set ratingNumber to 80
else if selectedRating = "★★★★★" then
set ratingNumber to 100
end if
set rating of targetTrack to ratingNumber
end tell
iTunes for Mac まとめ – AppleScriptを参考に作成。
tell application "iTunes"
set targetTrack to rating of current track
end tell
if targetTrack = 0 then
set hoshi to "・・・・・"
else if targetTrack = 20 then
set hoshi to "★・・・・"
else if targetTrack = 40 then
set hoshi to "★★・・・"
else if targetTrack = 60 then
set hoshi to "★★★・・"
else if targetTrack = 80 then
set hoshi to "★★★★・"
else if targetTrack = 100 then
set hoshi to "★★★★★"
end if
tell application "LaunchBar"
display in large type hoshi
delay 1
hide
end tell
LaunchBarでiTunesで再生中の曲を表示するスクリプト。
デフォルトで有るんじゃないかと思ったけど、どれかわからなかったし、ネットで調べなくてもすぐ作れそうというわけで自作。
tell application "iTunes"
set currentTrack to current track
set theName to name of currentTrack as text
set theArtist to artist of currentTrack as text
end tell
tell application "LaunchBar"
display in large type theName with title theArtist
delay 2
hide
end tell
表示がかっこよくない気が…。
ForkLiftがAppleScriptに対応してないのでLaunchBarがForkLiftに対応してない。ので、AppleScriptのkeystrokeでなんとか開けるようにした。
on open theString
set the clipboard to POSIX path of theString
tell application "ForkLift"
activate
end tell
tell application "System Events"
keystroke "g" using {command down, shift down}
keystroke "v" using command down
keystroke return
end tell
end open
これを/Users/r_izumita/Library/Application Support/LaunchBar/Actionsに保存して、LaunchBarのIndexを更新。LaunchBarでフォルダを選択してこのスクリプトを実行すると、ForkLiftでフォルダが表示される。
ファイルの親フォルダを表示する機能は未実装。
SafariでURLとTitleと選択している文字列を引用するためのAppleScriptを作ってみようと思います。
まずURLとTitleは
set t to name of document 1
set u to URL of document 1
で取得できました。
選択文字列はselectionで取得できるかと思ったら、どうやら無理のようです。で、考えられる方法は二つ。
- keystrokeかkey codeでcommand+cを送出してコピー
- JavaScriptでselectionを取得
ですね。今回はJavaScriptで取得してみます。
set theSelection to do JavaScript "unescape(escape(getSelection()));" in document 1
選択箇所がない場合はタイトルをリンク付きで取得。選択箇所がある場合はblockquoteで取得するようにしました。
tell application "Safari"
set theTitle to name of document 1
set theURL to URL of document 1
set theSelection to do JavaScript "unescape(escape(getSelection()));" in document 1
if theSelection is "" then
set theText to "<a href='" & theURL & "'>" & theTitle & "</a>"
else
set theText to "<blockquote cite='" & theURL & "' title='" & theTitle & "'>" & return & "<p>" & theSelection & "<cite><a href='" & theURL & "'>" & theTitle & "</a></cite></p>" & return & "</blockquote>" & return
end if
set the clipboard to theText as Unicode text
end tell
OmniFocusに決まった手順の作業を登録するときに毎回同じ事を入力するのは面倒なので、AppleScriptで自動化してみました。
front documentから入れるフォルダを得て、フォルダにプロジェクトを作成、さらにそのプロジェクトにアクションを作成、さらにさらにアクションにサブアクションを作成、というように追加していきます。
tell application "OmniFocus"
tell front document
set aFolder to folder "或フォルダ"
tell aFolder
set oProj to make new project with properties {name:"プロジェクト名"}
tell oProj
set oTask to make new task with properties {name:"アクション1"}
tell oTask
make new task with properties {name:"子アクション"}
end tell
make new task with properties {name:"アクション2"}
end tell
end tell
end tell
end tell