Skip to content

Instantly share code, notes, and snippets.

@azur256
Created May 25, 2012 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azur256/2785634 to your computer and use it in GitHub Desktop.
Save azur256/2785634 to your computer and use it in GitHub Desktop.
on run
tell application "Safari"
if (count of document) is greater than 0 then
tell window 1
set site_titles to {}
set site_records to {}
set loop_count to 1
repeat with handle_document in tabs
set site_title to name of handle_document
set site_title to replace_string_action(site_title, "最近, 気になったこと...: ", "") of me
set site_url to URL of handle_document
set site_record to {title_key:site_title} & {url_key:site_url}
set the end of site_titles to (loop_count & ": " & site_title) as string
set the end of site_records to site_record
set loop_count to loop_count + 1
end repeat
set selected_tabs to selected_item_indexes(site_titles) of me
insert_marsedit(site_records, selected_tabs) of me
end tell
end if
end tell
end run
on insert_marsedit(site_infos, select_indexes)
if select_indexes is equal to 0 then
return
end if
tell application "MarsEdit"
set insert_text to {"<ul>" & return}
repeat with select_index in select_indexes
set site_info to (item select_index) of site_infos
set site_title to title_key of site_info
set site_url to url_key of site_info
set encoded_title to replace_html_entity(site_title) of me
set the end of insert_text to ¬
" <li><a href=\"" & site_url & "\" title=\"" & encoded_title & "\" target=\"_blank\">" & encoded_title & "</a>" & make_tweetbuzz_url(site_url) of me & make_hateb_url(site_url) of me & "</li>" & return
end repeat
set the end of insert_text to {"</ul>"}
try
set selected text in document 1 to insert_text as text
end try
end tell
end insert_marsedit
on make_tweetbuzz_url(target_url)
set tweetBuzzURL to "<a href=\"http://tweetbuzz.jp/redirect?url=" & target_url & "\"><img src=\"http://tools.tweetbuzz.jp/imgcount?url=" & target_url & "\" /></a>"
return tweetBuzzURL
end make_tweetbuzz_url
on make_hateb_url(target_url)
set hatenaBURL to "<a href=\"http://b.hatena.ne.jp/entry/" & target_url & "\"><img src=\"http://b.hatena.ne.jp/entry/image/" & target_url & "\" /></a>"
return hatenaBURL
end make_hateb_url
on process_bundle_id(bundle_id)
tell application "System Events"
set a_process to every process whose bundle identifier is equal to bundle_id
if a_process = {} then
return false
end if
set a_process to contents of first item of a_process
return a_process
end tell
end process_bundle_id
on replace_string_action(target_text, before_string, after_string)
set orig_delimiter to AppleScript's text item delimiters
set AppleScript's text item delimiters to before_string
set tmp_list to every text item of target_text
set AppleScript's text item delimiters to after_string
set target_text to tmp_list as string
set AppleScript's text item delimiters to orig_delimiter
return the target_text
end replace_string_action
on replace_html_entity(target_text)
set target_text to replace_string_action(target_text, "&", "&amp;")
set target_text to replace_string_action(target_text, "<", "&lt;")
set target_text to replace_string_action(target_text, ">", "&gt;")
set target_text to replace_string_action(target_text, "\"", "&quot;")
return target_text
end replace_html_entity
on selected_item_indexes(target_list)
set dialog_message to "リストを作る項目を選択してください (Cmd + クリック で複数選択)"
try
set selected_items to choose from list target_list with prompt dialog_message with multiple selections allowed
on error
return
end try
if selected_items = false then return 0
set selected_indexes to {}
repeat with selected_item in selected_items
set the end of selected_indexes to selected_index(selected_item) of me
end repeat
return selected_indexes
end selected_item_indexes
on selected_index(selected_item)
set orig_delimiter to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set tmp_list to every text item of selected_item
set AppleScript's text item delimiters to orig_delimiter
return item 1 of tmp_list
end selected_index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment