This is part of a larger project to get info from a website and transfer some of it to Notes so that I can view it on my phone.
This small sample code creates a new Safari tab with the correct info, it selects all the text and copies it to the clipboard - all fine so far.
The new note is created but now I can’t get the focus to move to Notes for the Paste (Safari remains as top window).
Can someone help me with this please?
on write_to_file(the_file, the_data, with_appending)
set the_file to the_file as string
try
set f to open for access file the_file with write permission
if with_appending = false then set eof of f to 0
write the_data to f starting at eof as (class of the_data)
close access f
return true
on error the_error
try
close access file the_file
end try
return the_error
end try
end write_to_file
set noteName to "Test Note"
set the_html to "<body><h1 style=\"color:black;\">
<p><span style=\"color:#FF0000\">Some Notes </span>
<p><p><p>
<p><span style=\"color:#FF0000\">Some Pictures </span>
<p>
</h1>
</body>"
set the_file to (((path to desktop) as Unicode text) & "myQHSI.html")
my write_to_file(the_file, the_html, false)
tell application "System Events" to set the_URL to (get URL of (the_file as alias))
tell application "Safari"
open location the_URL
activate
delay 0.5
-- Copy the report from the new tab
tell application "System Events" to keystroke "a" using command down
tell application "System Events" to keystroke "c" using command down
delay 0.5
end tell
-- Create Note document
tell application "Notes"
set thisAccountName to "Icloud"
make new note at folder "Notes" of account thisAccountName with properties {name:noteName}
-- Paste to the new Note
activate
tell application "System Events"
tell process "Notes"
click menu item "Open Note in New Window" of menu "Window" of menu bar 1
delay 1
click menu item "Paste and Retain Style" of menu "Edit" of menu bar 1
end tell
end tell
end tell