Safari Address Bar query, help required please...

Hi there,

Just a quick query regarding Safari’s Address Bar. I’ve already read through a few posts but I’m not sure if I’ve hit the right thing.

If I type ‘http:’ in the Address Bar Safari displays a list of previous URL’s in a box below the Address Bar. Is there a way of saving them all to a list or output them to a text file?

I can see the URL’s in the box that’s displayed, it’s a question of how do I get at them?

Thanks in advance,

Nick

Hi Nick,

try this, tab browsing must be activated

set searchString to "http://www.Apple"
set theList to {}
activate application "Safari"
tell application "System Events"
	tell process "Safari"
		keystroke "t" using command down
		delay 0.2
		tell text field 1 of splitter group 1 of group 4 of tool bar 1 of window "Untitled"
			set value of attribute 6 to true
			repeat with i in characters of searchString
				keystroke i
			end repeat
			delay 0.5
			repeat
				key code 125
				keystroke "c" using command down
				delay 0.1
				set t to (get the clipboard)
				if theList is not {} then
					if last item of theList is searchString & t then exit repeat
				end if
				set end of theList to searchString & t
			end repeat
			key code 53 -- ESC
		end tell
	end tell
end tell

Hi Stefan,

Thanks for your reply and for the code which worked fine.

It got me thinking about something and so I went looking and wrote this:-

set addressList to {}
tell application "System Events"
	tell application process "Safari"
		set addressCount to (count of rows of table 1 of scroll area 1 of window 1)
		repeat with i from 1 to addressCount
			log i
			set addressList to addressList & (value of text field 1 of row i of table 1 of scroll area 1 of window 1) & return
		end repeat
	end tell
end tell

set the clipboard to addressList as text

Thanks again for your time with this query.

Regards,

Nick

Great, much better, I didn’t see the table of scroll area 1 :wink:

Thanks Stefan.

This was a last resort to try and track down a site I’d found and thought I’d bookmarked. I think I must have had a crash, hence no bookmark.
Hopefully, after some disection, I should be able to find it in the list I’ve got. :slight_smile:

Regards,

Nick

Why not just search your history.plist file in the safari folder?

Searching it isn’t too hard with the Terminal application and thus you can use applecscript. Here’s some terminal commands to help you…

– first you have to convert the binary plist file to a text format plist file, saved to the desktop
plutil -convert xml1 ~/Library/Safari/History.plist -o ~/Desktop/converted_history.plist

– then you can send it through grep to search it (my example search is for “applescript”)
cat ~/Desktop/converted_history.plist | grep -i “applescript”

Thanks for the suggestion and for the code which worked great.
Quite a good way of doing it and quite abit faster than my script version.

Thanks once again,

Nick