There’s a rather clumsy process for getting a URL link to a Notes.app note via the collaboration button. I’m wondering whether there’s a way to programmatically access that link in AppleScript. The dictionary shows that notes have an id property, but at least at first glance there doesn’t seem to be any connection between that id and the URL (unlike the case in Mail, for example). Does anyone know how to get the link without a lot of manual fiddling?
There is a simpler process (than described on the sites so far) to get a link to a Notes.app’s note placed in one of the folders on iCloud, without real sharing:
- Open Notes.app
- Select one of the notes of iCloud account
- Press collaboration button
- On pop up window select iMessages
- Press button “Share”
Popups window with link, which you can copy.
NOTE: No need to enter email address or to make real shared note. Only copy the link, then press “CANCEL”
All steps can be scripted BUT will involve UI Scripting with “System Events”. Steps 2) and 4) require third-party mouse tools too.
Here I wrote a script that uses 2 assumptions:
- You have the “Notes” application open and a note selected from the “iCloud” account.
- You have installed the utility “MouseTools”.
Here is the script, which would be better to convert into Quick Action (that is, custom Service), and which will open by right-clicking on the selected iCloud’s note:
set mouseToolsPath to "'Applications/MouseTools'"
tell application "Notes" to tell window 1
activate
set zoomed to true -- ENTER ZOOMED SCREEN MODE
end tell
tell application "System Events" to tell application process "Notes"
click UI element 10 of toolbar 1 of window "Notes" -- CLICK COLLABORATION BUTTON
-- WHAIT UNTIL WINDOW "Add People" BECOMES ACTIVE
repeat until exists window "Add People"
delay 0.1
end repeat
do shell script mouseToolsPath & " -x 558 -y 388 -leftClick" -- SELECT "MESSAGES"
click UI element "Share" of window "Add People" -- CLICK "SHARE" BUTTON
-- WHAIT UNTIL WINDOW "Messages" BECOMES ACTIVE
repeat until exists window "Messages"
delay 0.1
end repeat
tell text field "To:" of scroll area 1 of window "Messages"
keystroke return -- GO FOCUS TO THE LINK SCROLL AREA
end tell
-- COPY LINK SCROLL AREA CONTENTS TO THE CLIPBOARD
click menu item "Select All" of menu 1 of menu bar item "Edit" of menu bar 1
click menu item "Copy" of menu 1 of menu bar item "Edit" of menu bar 1
-- CLOSE WINDOW "Messages", NO NEED REAL SHARING
click UI element "Cancel" of window "Messages"
end tell
-- GET THE URL
set myURL to paragraph 2 of (the clipboard as text)