Skip to content

Action Scripts Guide

Stephen Kaplan edited this page May 12, 2023 · 1 revision

Examples

Example 1 - Add Summary To Current Note

Prompt

Output a two-sentence summary of this note:
###
{{as:tell application "Notes" to get body of item 1 of (selection as list)}}
###

Action Script Code

tell application "Notes" to set body of item 1 of (selection as list) to (body of item 1 of (selection as list)) & "<br/><br/><b>Summary:</b> " & response

Description

This command generates a short summary of the currently selected note in Notes.app and appends it to the end of the note. To do this, the command first instructs the AI to output a two-sentence summary of the selected note's contents. The action script then appends the summary to the end of the note's body text, preceded by a bolded "Summary:" label and a double line break. The result is a note that has a brief summary at the end, like this:

Screenshot 2566-05-12 at 19 32 48

Example 2 - Create Keynote From File

Prompt

Generate several slideshow slides based on the content of these files. Organize the slides by topic. Label each slide with a creative title.
The first slide will be a title slide with the following format. Replace text between [] with content from the files.

"[slideshow title]\n[subtitle]"

All other slides must use this format:

"[slide title]\n[item 1]\n[item 2]\n[item 3]"

Separate each slide with '-----'. Do not provide any other commentary or labels.

Action Script Code

set theSlides to split(trim(response), "-----")
tell application "Keynote"
  activate
  set theDoc to make new document
  
  tell theDoc
    repeat with theSlideContent in theSlides
      set subbedContent to my replaceAll(theSlideContent, "", "")
      set subbedContent to my replaceAll(theSlideContent, "#", "")
      set theSlide to make new slide
      tell theSlide
        set theLines to my split(my trim(subbedContent), "
")
        if length of theLines is 0 then
          delete theSlide
        else
          set default title item's object text to item 1 of theLines
          if length of theLines > 1 then
            set oldDelims to AppleScript's text item delimiters
            set AppleScript's text item delimiters to "
"
            set default body item's object text to (items 2 thru end of theLines) as text
            set AppleScript's text item delimiters to oldDelims
          else
            delete text item 3
          end if
          delete text item 2
        end if
      end tell
    end repeat
    delete slide 1
  end tell
end tell

Description

This command creates a simple Keynote slideshow based on the contents of the currently selected files. To do this, the command instructs the AI to separate the topics of each file into slides, with each slide separated by a line of dashes. The first line of each slide is used as the title of the slide, and the remaining lines make up the list of bullet points relevant to that slide. The action script then takes the AI's response and splits it along the dashes, using the provided split handler. Extraneous bullet markers in the text are removed using the provided replaceAll handler so as to avoid duplicate markers in the final result. The cleansed text of each slide is then split into individual lines, and the first line is used as the slide title. The remaining lines are joined together and used as the bullet points of the slide. Each slide gets added to the newly created document, and the first slide is deleted, as it is the default title slide and is no longer needed. At the end of the command's execution, the user will be looking at a new Keynote document that provides a general overview of the topics covered in the selected files, like this:

Screenshot 2566-05-12 at 19 37 20