Jump to content

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


Recommended Posts

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
Link to comment
  • 2 weeks later...

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
Link to comment

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

 

 

Link to comment

           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
Link to comment

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.)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...