Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Easier way | 13 comments | Create New Account
Click here to return to the 'Easier way' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Easier way
Authored by: Krioni on Jan 24, '03 04:56:44PM

Here's some code you can save as a Stay-Open applet. It lets you load a return-delimited list of URLs from the clipboard, or from a text file, and opens them in your default browser. It's up to the browser settings to open in new windows. That is Safari's default behavior.

on run
-- version 1.1, Daniel A. Shockley (http://www.danshockley.com)
set loadChoice to button returned of (display dialog "Load from File, Clipboard, or Quit" buttons {"Quit", "Clipboard", "File"} default button "File")
if loadChoice is "Quit" then
tell me to quit

else if loadChoice is "Clipboard" then
--load from clipboard instead of file
my loadURLs({sourceType:"clipboard"})
continue activate
else -- "File"
my loadURLs({sourceType:"file"})
continue activate
end if
end run

on reopen
set loadChoice to button returned of (display dialog "Load from File, Clipboard, or Quit" buttons {"Quit", "Clipboard", "File"} default button "File")
if loadChoice is "Quit" then
tell me to quit

else if loadChoice is "Clipboard" then
--load from clipboard instead of file
my loadURLs({sourceType:"clipboard"})
continue activate
else -- "File"
my loadURLs({sourceType:"file"})
continue activate
end if
end reopen



on loadURLs(prefs)
-- version 1.1
try
set defaultPrefs to {sourceType:"file"}
set prefs to prefs & defaultPrefs

if sourceType of prefs is "file" then
set listOfURLs to getListofURLsFromFile()
else if sourceType of prefs is "clipboard" then
set listOfURLs to getListofURLsFromClipboard()
else -- unknown sourceType
error "Unknown sourceType for getting URL list."
end if
return sendURLs(listOfURLs)
on error errMsg number errNum
error errMsg number errNum
end try
end loadURLs


on getListofURLsFromClipboard()
try
set blockOfURLs to (get the clipboard)
try
set blockOfURLs to blockOfURLs as string
on error
set blockOfURLs to ""
end try

if blockOfURLs is "" then
tell me to activate
display dialog "The clipboard could not be converted into text. Please copy your list of URLs and try again."
return false
end if
-- just in case file or clipboard is using UNIX-style line endings
set blockOfURLs to simplereplace(blockOfURLs, ASCII character 10, return)

set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set listOfURLs to text items of blockOfURLs
set AppleScript's text item delimiters to od
return listOfURLs
on error errMsg number errNum
error errMsg number errNum
end try

end getListofURLsFromClipboard

on getListofURLsFromFile()
try
set prefFilePath to (choose file with prompt "Choose a file of return-delimited URLs") as string
set blockOfURLs to readFileByPath(prefFilePath)
if blockOfURLs is "" or testPathExists(prefFilePath) is false then
tell me to activate
display dialog "There are no saved URLs to open. The preference file is at " & prefFilePath
return false
end if
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set listOfURLs to text items of blockOfURLs
set AppleScript's text item delimiters to od
return listOfURLs
on error errMsg number errNum
error errMsg number errNum
end try
end getListofURLsFromFile


on sendURLs(listOfURLs)
try
repeat with oneURL in listOfURLs
open location oneURL
delay 1
end repeat
return true
on error errMsg number errNum
error errMsg number errNum
end try
end sendURLs

on readFileByPath(someFilePath)
-- version 1.0
try
set fileHandle to open for access file someFilePath

set fileContents to read fileHandle
close access fileHandle
on error errMsg number errNum
try
close access fileHandle
end try
if errNum is -39 then
set fileContents to ""
else
error errMsg number errNum
end if
end try
return fileContents
end readFileByPath

on testPathExists(inputPath)
-- version 1.4
-- from Richard Morton, on applescript-users@lists.apple.com
-- public domain, of course. :-)
-- gets somewhat slower as nested-depth level goes over 10 nested folders
if inputPath is not equal to "" then try
get alias inputPath as string
return true
end try
return false
end testPathExists

on simplereplace(thisText, oldChars, newChars)
-- version 1.1, Daniel A. Shockley http://www.danshockley.com

-- 1.1 coerces the newChars to a STRING, since other data types do not always coerce
-- (example, replacing "nine" with 9 as number replaces with "")
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to the oldChars
set the parsedList to every text item of thisText
set AppleScript's text item delimiters to the {(newChars as string)}
set the newText to the parsedList as string
set AppleScript's text item delimiters to oldDelims
return newText
end simplereplace



[ Reply to This | # ]
Easier way
Authored by: tngland on Jan 26, '03 08:22:34PM

My approach had alway been to create Applescripts, although I found each browser expected slight variations within the scripts.
Since Chimera/Navigator, though I find it much simple to create a window with the sites I want to grouped all tabbed. Then I use the "Bookmarks All Tabs" to create a single bookmark (which I can name) for all those sites. These are much easier to create, alter & access.

One of my favorites I only use on Sunday mornings. It's a grouping of the Travel, Arts & magazines sections of a number of newspapers.



[ Reply to This | # ]
Easier way
Authored by: luhmann on Apr 17, '03 09:48:14PM

Anyone figure out a "bookmark all tabs" applescript for Safari?

This site has a lot of nice safari scripts, but not that one:

http://www.apple.com/applescript/safari/



[ Reply to This | # ]