r/applescript • • Sep 19 '22

tiny apple script for Safari 16

I had a working script but with updating to Safari 16 it stopped working.All i want to achieve is saving a couple of mouse clicks and mouse movements: saving the current site to a note.

tell application "System Events"  
 tell process "Safari"  
 set frontmost to true  
 click menu item "Notes" of menu of menu item "Share" of menu "File" of menu bar 1  
 end tell  
end tell  

seems not to be able to find the "Notes" in submenu "Share", how come ?

5 Upvotes

24 comments sorted by

View all comments

Show parent comment

1

u/estockly Sep 20 '22

Based on ChristoferK's script:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property notesFolderName : "High-performance sailing"
tell application "Safari" to tell the front document ¬
to set website to {title:name, href:URL}
tell application "Notes" to tell the default account
set SafariFolder to a reference to the ¬
folder named notesFolderName
if not (the SafariFolder exists) then make new folder ¬
with properties {name:notesFolderName}
tell the SafariFolder to tell (make new note with properties {name:¬
the website's title, body:"<div><h2>" & website's title & ¬
"</h2><h4><b><a href=\"" & the website's href & "\">" & ¬
the website's title & "</a></b></h4><p>Saved on " & ¬
((current date) as «class isot» as string) & "</p></div>"})
end tell
end tell
display notification the website's href with title ¬
"Note created." subtitle the website's title