HOME > AppleScript > Safari で開いている全ての URL からロケーションファイルを作成


(*
@Mac OS X 10.4.5
GUI スクリプティング有効
*)

global urlList
set urlList to {}
global docNameList
set docNameList to {}

tell application "Safari"
activate
display dialog "" buttons {"Cancel", "Current page", "All"} default button 3
if button returned of result is "Current page" then
set urlList to (urlList & (URL of document 1))
set docNameList to (docNameList & (name of document 1))
my createFile()
else
my everyWindow()
my createFile()
end if
end tell

on createFile()
set folderName to "webloc-" & (do shell script "date \"+%Y%m%dT%H%M%S\"")
set folderName to my existsBool(folderName, (path to desktop folder) as Unicode text)
tell application "Finder"
set newFolder to (make new folder at (path to desktop folder) with properties {name:folderName})
repeat with i from 1 to (number of items of urlList)
set theTitle to (do shell script "echo " & quoted form of (item i of docNameList) & " | sed 's/^\\./_/;s/\\//_/g;s/\\:/_/g'")
make new internet location file at (newFolder as alias) to (item i of urlList) with properties {name:theTitle}
end repeat
activate
reveal newFolder
end tell
end createFile

on everyWindow()
tell application "System Events"
tell process "Safari"
set meNum to (number of menu items of menu 1 of menu bar item 8 of menu bar 1)
repeat
set curMenu to name of menu item meNum of menu 1 of menu bar item 8 of menu bar 1
try
curMenu
click menu item meNum of menu 1 of menu bar item 8 of menu bar 1
my switchTabs()
set meNum to (meNum - 1)
on error
exit repeat
end try
end repeat
end tell
end tell
end everyWindow

on switchTabs()
tell application "System Events"
tell process "Safari"
tell window 1
if exists (button 1 of group 3) then
set btnCnt to number of buttons of group 3
repeat with i from 1 to btnCnt
click button i of group 3
my getTheURL()
end repeat
else
my getTheURL()
end if
end tell
end tell
end tell
end switchTabs

on getTheURL()
tell application "Safari"
--delay 1
try
set curDoc to (document of window 1)
curDoc
set curURL to (URL of document 1)
curURL
set urlList to urlList & (URL of document 1)
set docNameList to docNameList & (name of document 1)
on error
beep
end try
end tell
end getTheURL

on existsBool(itemName, contFolder)
tell application "Finder"
if exists folder (contFolder & itemName) then
set num to 2
repeat
set itemName to (itemName & " " & (num as Unicode text))
if not (exists folder (contFolder & itemName)) then
exit repeat
else
set num to (num + 1)
end if
end repeat
end if
end tell
return itemName
end existsBool

--参考
--MacScripter BBS | Applescript Forums :: View topic - applescript editor for Windows 2000 - create alias
--http://64.233.179.104/search?q=cache:_IESWvq_e1EJ:bbs.applescript.net/viewtopic.php%3Fp%3D18902%26sid%3D0301c0a74bd8f6bd9e4555f7194a1270+applescript+%22location+file%22+make&hl=ja&ct=clnk&cd=3&client=safari

HOME > AppleScript > Safari で開いている全ての URL からロケーションファイルを作成

TOP

created: 2006-03-08T00:55:24+09:00
last modified: 2006-04-04T00:31:55+09:00
author: AquaBowler