Jump to content
nplanchon

Creation of keyboard shortcut to send url to (Apple) Notes app

Recommended Posts

Hello everyone - I would like to learn how to create a keyboard shortcut which would make it possible for me, whilst in safari at a url, to send that url to Notes for future reading and reference.

 

Thank you

Neil

Share this post


Link to post

This script gets the URL of the current Safari page and creates a new note in Notes.app containing the URL.
 
Put it in a Run Script action with Language = /usr/bin/osascript (AS), the attach it to a Keyword/Hotkey of your choice. 
 

property accountName : "iCloud"
property folderName : "Notes"

on getSafariUrl()
    tell application "Safari" to return URL of front document
end getSafariUrl

on addNote(theText, theTitle)
    tell application "Notes"
        tell account accountName
            set theNote to make new note at folder folderName with properties {body:theText, name:theTitle}
        end tell
    end tell
end addNote

on run (argv)
    set theUrl to my getSafariUrl()
    my addNote(theUrl, "URL from Safari")
end run

Share this post


Link to post

hi,

 

Took the chance and expanded the above script a little, and probably it could be streamlighted: 

 to get the title(or name) of the Safari page as Notes title:

 

---

 

property accountName : "iCloud"

property folderName : "Notes"

 

on getSafariUrl()

tell application "Safari" to return URL of front document

end getSafariUrl

 

on getSafariTitle()

tell application "Safari" to return name of front window

end getSafariTitle

 

on addNote(theText, theTitle)

tell application "Notes"

tell account accountName

set theNote to make new note at folder folderName with properties {body:theText, name:theTitle}

end tell

end tell

end addNote

 

on run (argv)

set theUrl to my getSafariUrl()

set theTitle to my getSafariTitle()

my addNote(theUrl, theTitle, "URL from Safari")

end run

 

--------

 

/

with best regards,

Omar K N

 

( a beginner )

Edited by OmarKN

Share this post


Link to post

Let me add the following:

 

The above tweak creates a new note in Notes app with the url in the note body and the title as the name of the note - which is fine!

 

However, I'd prefer an additional line in the body: the title.

 

To look like this in the note:

 

------

 

Stay at home dads are all right by me

 
------
 
 
with the title as the name of the note.
 
 
How would this be done?
 
/

with best regards,

Omar K N

Stockholm, Sweden

 

 

Share this post


Link to post

           property accountName : "iCloud"

property folderName : "Notes"

 

-- Return title and URL of current Safari page

on getSafariPage()

    tell application "Safari"

        set theURL to URL of front document

        set theTitle to name of front document

    end tell

    return {link:theURL, title:theTitle}

end getSafariPage

 

-- Add note to Note.app

-- the body of the note it theTitle + theText

on addNote(theText, theTitle)

    set theBody to theTitle & return & theText

    tell application "Notes"

        tell account accountName

            set theNote to make new note at folder folderName with properties {body:theBody, name:theTitle}

        end tell

    end tell

end addNote

 

on run (argv)

    set pageInfo to my getSafariPage()

    my addNote(link of pageInfo, title of pageInfo)

end run

Edited by deanishe

Share this post


Link to post

Hi and good day Dean,

 
 
So far - excellent!
 
 
However, I wonder if the script can be tweaked just a little?
 
 
Sometimes (~ 50%) in the body of the note (Apple Notes) the title and the url flow after each other like this:
 
A Screenshot Is Worth a Thousand Words – MacStories https://www.macstories.net/roundups/a-screenshot-is-worth-a-thousand-words/
 

 

 
Would it not be more beautiful with a new line break of some sort, so it will always look like this:
 
A Screenshot Is Worth a Thousand Words – MacStories 
 

 

I thought stuffing in a linefeed somewhere, but - of course - no success :-)

 

/

okn

(It's a new year 2016.)

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...