Skip to content

Instantly share code, notes, and snippets.

@moyashi
Created May 26, 2011 21:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moyashi/994138 to your computer and use it in GitHub Desktop.
Save moyashi/994138 to your computer and use it in GitHub Desktop.
Firefoxで表示中のページタイトルとURLをカーソル位置にリンクで貼り付けるTypeIt4Me( http://bit.ly/iorZdU )用スクリプト
--「システム環境設定>ユニバーサルアクセス>補助装置にアクセスできるようにする」のチェックボックスをONにする必要あり
--また、環境によってdelay1, delay2を調整する必要があるかもしれません
global format
global delay1
global delay2
--リンクの書式を変える場合はformatを変更
set format to "<a href=\"$url$\" target=\"_blank\">$title$</a>"
set delay1 to 0.1
set delay2 to 0.5
set isRunning to my isRunning("firefox-bin")
if (isRunning) then
my do()
end if
on do()
tell application "Firefox"
if ((count of windows) is greater than 1) then
set t to name of window 1
else
return
end if
activate
end tell
set oldclp to (the clipboard)
repeat 20 times
tell application "Firefox"
set fm to frontmost
end tell
if (fm) then
my copyUrl()
exit repeat
end if
delay delay1
end repeat
delay delay2
set tmp to my replace(format, "$title$", t)
set tmp to my replace(tmp, "$url$", (the clipboard))
set the clipboard to tmp
my paste()
set the clipboard to oldclp
end do
on paste()
tell application "System Events"
try
key down command
delay delay1
keystroke tab
key up command
delay delay2
key down command
delay delay1
keystroke "v"
delay delay1
key up command
on error
key up command
end try
end tell
end paste
on copyUrl()
tell application "System Events"
tell process "firefox-bin"
try
key down command
delay delay1
keystroke "l"
delay delay1
keystroke "c"
delay delay1
key up command
on error
key up command
end try
end tell
end tell
end copyUrl
on isRunning(appname)
tell application "System Events"
return (count of (every process whose name contains appname)) is greater than 0
end tell
end isRunning
on replace(str, org, rep)
try
set oldDel to AppleScript's text item delimiters
set AppleScript's text item delimiters to org
set myList to text items of str
set AppleScript's text item delimiters to rep
set res to myList as string
set AppleScript's text item delimiters to oldDel
on error
set AppleScript's text item delimiters to oldDel
end try
return res
end replace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment