Grab URL Script Redeux
John Gruber has posted a “Grab URL” script for BBEdit, handy when working in BBEdit and you’d like to grab an existing page’s code. His script, however, requires you to enter in your own URL by hand or by copy/paste. I thought it’d be neat if it auto-magically grabbed Safari’s top-most URL instead. This could easily be written for Camino, I’m sure. Anyhoo, if you want it, get it here and drop it in your /Applications/BBEdit/BBEdit Support/Scripts folder. It’ll show up in the “Scripts” menu un BBEdit, strangely enough.
Now, this does a little bit of checking to see if Safari is actually running. If it’s not running, it just gives you the empty text field as before. This will only work correctly if Safari is somewhere (anywhere) within your /Applications directory. It was the quickest way I could think of to do it. I gotta say, I like AppleScript’s string search capability much more than the traditional Regular Expression baloney you have to wade through in PHP or JavaScript, even when you’re just doing a simple search.
The UPDATED source is below:
-- originally written by John Gruber
-- at daringfireball.net to just be an
-- empty text field
-- edited by kevin conboy at alternate.org
--to automatically take the top-most URL in safari
-- DOES NOT WORK WITH SAFARI'S TABS
-- I'm sure someone can get it to work with
-- GUI Scripting beta, though
tell application "System Events"
set proclist to creator type of every process
if proclist contains "sfri" then
tell application "Safari"
set safari_url to URL of document 1
end tell
else
set safari_url to ""
end if
end tell
tell application "BBEdit"
set my_result to display dialog ¬
"URL:" default answer safari_url ¬
buttons {"Cancel", "With Headers", "Grab Source"}¬
default button 3
set my_url to the text returned of my_result
if button returned of my_result is "With Headers" then
set my_text to do shell script ("curl -i " & my_url)
else
set my_text to do shell script ("curl " & my_url)
end if
make new text window with properties {contents:my_text,¬
name:my_url}
select insertion point before character 1 of text window 1
end tell
Reader interactions
3 Replies to “Grab URL Script Redeux”
Comments are closed.
“A scripting error occurred: Can’t make some data into the expected type.”
Or at least that’s what it tells me for alternate.org…
did you download the SIT file? Are you using MacOS X? It’s probably best to download the file instead of just copying and pasting the script from the page. Also, this script requires MacOS X and I believe BBEdit 7.
I just downloaded the SIT file, dropped it into the directory again, restarted BBEdit and it worked like a charm. Let me post an updated version that doesn’t use unix to find if safari’s running.
ok, there’s a newer version up. however, i had problems with safari caching the sit file. empty your cache before you go and download the new version.