Tuesday, September 27, 2022

#1 2022-09-11 02:26:23 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2524

Notes.app: Save notes's attachments at chosen folder.

No need to bother with GUI scripting like here: Save Notes attachment.

enjoy:

Applescript:


-- here I choose desktop folder, for example
set destinationFolder to (path to desktop folder) as text

tell application "Notes"
   set theAttachments to a reference to attachments of notes
   repeat with theAttachment in theAttachments
       try -- some notes have not attachments, so try block need
           save theAttachment in file (destinationFolder & name of theAttachment)
       end try
   end repeat
end tell

The script above saves all attachments of all notes of Notes.app.

Following version will save only the attachments of chosen (in Notes.app GUI) note:

Applescript:


on getNotesSelection()
   tell application "Notes"
       if ((count of windows) = 1) or (name of window 1 is "Notes") then
           if "4.7"its version then -- `selection` property not compatible before MacOS 10.15
               if (count of selection) = 1 then
                   set noteID to «class seld» of (selection as record)
                   set noteContainerID to «class seld» of ((container of note id noteID) as record)
                   set selectedNoteName to name of note id noteID
                   set selectedNoteFolderName to name of folder id noteContainerID
               else
                   -- multiple notes selected
                   return ""
               end if
           end if
       end if
   end tell
   return {note_Name:selectedNoteName, folder_Name:selectedNoteFolderName}
end getNotesSelection

set note_Name to note_Name of getNotesSelection()

-- here I choose desktop folder, for example
set destinationFolder to (path to desktop folder) as text

tell application "Notes"
   set theAttachments to a reference to attachments of note named note_Name
   repeat with theAttachment in theAttachments
       try -- some notes have not attachments, so try block need
           save theAttachment in file (destinationFolder & name of theAttachment)
       end try
   end repeat
end tell

Last edited by KniazidisR (2022-09-11 02:40:51 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)