Apple script to send URL and title of the active tab to an Apple note

Apple script to send URL and title of the active tab to an Apple note.

I can use the script (below) to get the URL from the active tab of Chrome and send it to Apple Notes. The body of the Note is the URL from the active tab.

Q1: How do I make the URL in the note into a clickable link?
Q2: I would like to show a link preview for the link. Is it possible?

tell application "Google Chrome"
    if it is running then
        -- Get the URL and title of the active tab
        set currentURL to URL of active tab of front window
        set currentTitle to title of active tab of front window
        
        -- Create the note content
        set noteContent to currentURL
        
        -- Send to Notes app
        tell application "Notes"
            tell account "Google" -- can change to the name of an existing account
                tell folder "Links" -- first make the folder if it does not exist
                    make new note with properties {name:currentTitle, body:noteContent}
                end tell
            end tell
        end tell
        
    else
        display alert "Chrome is not running"
    end if
end tell

Hi @paulstgeorge. Welcome to MacScripter.

My own HTML knowledge is a little rusty, but the following does create a clickable link in the note, the link text being the same as the title and the destination being the URL. I’ve no idea about link previews, I’m afraid. :face_with_diagonal_mouth:

tell application "Google Chrome"
	if (it is not running) then return (display alert "Chrome is not running") -- returns the button pressed
	
	-- Get the URL and title of the active tab
    set currentURL to URL of active tab of front window
    set currentTitle to title of active tab of front window
end tell

-- Create the note content
set noteContent to "<a href=\"" & currentURL & "\">" & currentTitle & "</a>"

-- Send to Notes app
tell application "Notes"
    tell account "Google" -- can change to the name of an existing account
    	tell folder "Links" -- first make the folder if it does not exist
        	make new note with properties {name:currentTitle, body:noteContent}
    	end tell
    end tell
end tell
2 Likes

Excellent. Thank you.
Now I know it is html, I will work on getting a link preview from the webpage. If/when I succeed, I’ll share here.