Write an AppleScript to create a web link on the desktop

applescriptsafari

I'm helping a visually impaired friend learn how to use her Mac. She's using the built-in screen magnifier, which is working great. She likes to access websites (mainly TV streaming services) via links on her desktop, which I'm able to create by hand. However the standard method for creating these (dragging a URL from the location bar in Safari to the desktop) isn't ideal for a visually impaired user.

I was thinking, therefore, that maybe I could write an AppleScript which could create the weblink on the desktop. I'd envisage this script being run from Safari when the user hits a specific keystroke. I've got no experience of writing AppleScript, however. Is it the best approach for what I'm trying to do? How should I go about getting started?

Best Answer

This script will do what you asked. It grabs the URL and the Name of the current Safari tab and creates a weblink file on the desktop. It uses the page's name to name the file. If you want help parsing a better option for the file name, just ask.

try -- will just silently quit if front window is not valid
tell application "Safari"
    set theURL to URL of current tab of window 1
    set theName to name of current tab of window 1
end tell

tell application "Finder"
    make new internet location file at desktop to ¬
        theURL with properties {name:theName}
end tell
end try