Sunday, December 4, 2022

#1 2022-10-29 08:01:23 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 1091

Make table in Notes

Simple script to make a note in specified folder with table. The script use repeat loop.
So the user could build category and values to feed data to table.

Ps. There is a bug in Note so I had to make dummy make note propery if the folder is empty.

Applescript:

set {theCategorys, theValues} to {{"Food", "Shopping", "Arduino"}, {"2000 kr", "600 kr", "500 kr"}}

its makeNoteInFolder:"MyNotes" tableTitle:"Table 1" categorys:theCategorys itsValues:theValues

(**
* [makeNewNoteInFolder:string folderName tableTitle:string tableTitle categorys:list theCategorys itsValues:list theValues]
*)

on makeNoteInFolder:folderName tableTitle:tableTitle categorys:theCategorys itsValues:theValues
   set theStart to "<div><object><table cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse: collapse; direction: ltr\">
<tbody>"

   
   set tableString to ""
   repeat with i from 1 to count theCategorys
       set theTable to "
   <tr><td valign=\"top\" style=\"border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #ccc; padding: 3.0px 5.0px 3.0px 5.0px; min-width: 70px\"><div>"
& (item i of theCategorys) & "</div>
   </td><td valign=\"top\" style=\"border-style: solid; border-width: 1.0px 1.0px 1.0px 1.0px; border-color: #ccc; padding: 3.0px 5.0px 3.0px 5.0px; min-width: 70px\"><div>"
& (item i of theValues) & "</div>
   </td></tr>"

       set tableString to tableString & theTable & linefeed
   end repeat
   
   set theEnd to "</tbody>
</table></object><br></div>"

   
   set tableBody to theStart & tableString & theEnd
   
   tell application "Notes"
       tell folder folderName
           -- There is a bug in Notes...
           set countNotes to count note
           if countNotes < 1 then
               make new note at end with properties {name:""}
           end if
           
           set theNote to make new note at end with properties {name:tableTitle, body:tableBody}
           
           -- if the countNote was < 1
           if countNotes is 0 then
               delete note "New Note"
           end if
       end tell
   end tell
end makeNoteInFolder:tableTitle:categorys:itsValues:

Last edited by Fredrik71 (2022-10-29 10:50:33 am)


Node-RED makes it easy to automate IoT

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)