Cheers jdr,
thanks for sharing this, I've used it so often!
(I configured my Safari to open links in new tabs, which is my preferred way of browsing the web when I'm in a window of the current context anyways. But I was always annoyed when Alfred queries send me to a different desktop space and/or maximizes a totally unrelated Safari window full of tabs).
As I was missing a couple of features, I took your workflow and extended the script a little bit, so it accepts a parameter which can be:
- empty (just opens a new window)
- a search string (opens google, but you can change this in the script)
- an URL (a string containing one of these substrings: http:, www., .com, .edu, .net, .org... )
Update Aug 2016:
- prepends "http://" if missing and some of the TLDs are detected (.com, .edu, .net, .org, .de, ... )
Hope someone likes it, I'm using it really often.
You might want to change the trigger key though, it's "safari"
http://www.audiocommander.de/.../Safari%20Window.alfredworkflow
(or just the Apple Script part)
on alfred_script(q)
tell application "Safari"
if "http:" is in q or "www." is in q or ".com" is in q or ".de" is in q or ".edu" is in q or ".net" is in q or ".org" is in q then
if q starts with "http://" or q starts with "https://" then
make new document with properties {URL:q}
else
make new document with properties {URL:"http://"&q}
end if
else
make new document with properties {URL:"http://www.google.com/search?q="&q}
end if
activate
end tell
end alfred_script