Thursday, June 4, 2020

#1 2020-03-31 07:18:16 am

Ludovic
Member
Registered: 2020-03-28
Posts: 2

Safari Web Clipping to Notes

This is my first post!

Dear Community,

I am trying to write a simple scrip to bee able to clip the equivalent of the reader view of a safari article into a new note. After trying multiple ways through the reader view, I have reverted to a more - brutal way.

It seems that I can't directly copy the 'source' of Document 1 (the front window) into the 'body' of a new note because the types do not match.

Any idea how to unlock this problem?
Thanks

Applescript:

tell application "System Events"
   tell application process "Safari"
       
       tell application "Safari" to set theTab to current tab of window 1
       
       set frontmost to true
       --        tell menu bar 1
       --            click menu item "Show Reader" of menu "View" of menu bar item "View"
       -- click menu item "Save As…" of menu "File" of menu bar item "File"
       --        end tell
       
       -- tell application "Safari" to set the clipboard to (text of current tab of front window) as string    
       set NoteNameString to name of theTab
       
       --            repeat until sheet 1 exists
       --            end repeat
       --            tell sheet 1
       -- set NoteNameString to "Test Note 1"
       -- set NoteContentString to text of tab of front window
       
       if document 1 exists then
           set NoteContentString to the source of document 1
       end if
       
       -- tell menu bar 1
       --    click menu item "Hide Reader" of menu "View" of menu bar item "View"
       -- click menu item "Save As…" of menu "File" of menu bar item "File"
       -- end tell
       
       tell application "Notes"
           set theNoteID to make new note in folder "Notes" with properties {name:NoteNameString, body:NoteContentString}
       end tell
       
   end tell
end tell


Filed under: safari, notes

Offline

 

#2 2020-03-31 10:12:32 am

Ludovic
Member
Registered: 2020-03-28
Posts: 2

Re: Safari Web Clipping to Notes

Hello,

I found a way to make it happened!

[applescript]
tell application "System Events"
    tell application process "Safari"
       
        tell application "Safari" to set {theSource, theTitle} to {source, name} of current tab of window 1
       
        set NoteNameString to theTitle
        set NoteContentString to the theSource
       
        tell application "Notes"
            set theNoteID to make new note in folder "Notes" with properties {name:NoteNameString, body:NoteContentString}
        end tell
       
    end tell
end tell

[/AppleScript]

I still need to clean-up the text to make it look like the clean Reader version. Stepping up my looking at a Javascript script at:
http://blog.manbolo.com/2013/03/18/safari-reader.js

I am going to try to have it run on the source extracted from the page before creating the Note.


Filed under: safari, notes

Offline

 

#3 2020-03-31 10:29:41 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11686
Website

Re: Safari Web Clipping to Notes

To copy the source of the current tab into a new note these lines are sufficient.

You have to specify also the account name because Notes is the default folder of any account

Applescript:

tell application "Safari" to set {source:theSource, name:tabName} to current tab of window 1
tell application "Notes"
   set theNoteID to make new note in folder "Notes" of account "iCloud" with properties {name:tabName, body:theSource}
end tell

But neither the text nor the source are the exact equivalent of the reader view


regards

Stefan

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)