I finally got around to adding some pointers, arising from forum discussions, into the aTbRef section on Applescript. Thanks to all forum member cotributing their expertise and, in particular, thanks to @sumnerg .
Drawing on some helpful feedback, Iāve expanded the AppleScript a bit more and broken some of the larger articles into smaller ones allowing for better linking.
Question/corrections welcome. I think the four articles on objectsā properties could probably do with a simple explanatory code example to indicate the syntax. Code suggestions welcomed!
The TBX zip, search index and sitemap are all updated.
Side note; Iāve adjusted the site CSS so the grey background to <code> elements is a bit lighter to give better contrast balance from the white page background and to the dark red text.
What Iāve tried to dig into with the code examples is the fine detail of the code syntax. AppleScriptās app dictionary UI lacks such info so having to guess the code to write is a bore. I suspect that missing info also nerfs general occasional use of AppleScript except to run othersā completed scripts.
An interesting example, realised from this re-write, AppleScript doesnāt let you describe a note by its $Path. Instead you have to āfindā (find note in operator) the note at the path and make a variable of that object and then use the latter. You can write it as a one liner, but the line gets very long and hard to read. Also there is no copy/duplicate method, though one can communicate with the appās menu using general AppleScript menus. I also noted the appās AS dictionary has no notion of aliases (so, making an alias would have to use menu interaction). Perhaps I need to add an article with a non-exhaustive list of unsupported note management tasks?
That might include:
- Making aliases. A workaround is to make an agent to find only the to-be-aliased note, move the child alias to a desired place then deleting the agent. Existing aliases are addressed as if actual notes, being aware that an alias/original state can be checked by reading its $IsAlias value.
- Copying notes/agents/adornments. Here, I think using AppleScript
System Eventsto drive the menus is the workaround. - Adding ābuilt-inā features (as from app file menu). Again, use AppleScript
System Eventsā . - making/deleting links. The appās dictionary is mainly for dealing with existing links. Currently this task has to be effected via an āevaluateā call (akin to action code eval) on action code operatorsāi.e. the expression being evaluated as in the code example here.
The point of the above list is not to militate for loads more built-in AppleScript dictionary functionality (as the ROI for that isnāt clear) but to indicate, for those making occasional try-out of AppleScript use, that a solution is possible even if not via a single baked-in code. Using System Events makes very verbose code that is new-user unfriendly, thus the suggestion in the footnote.
ā . Perhaps some AS-competent person would like to write a pair of AS sub-routines (aka functions) for calling menu items or menus sub-menu items akin to those seen in this answer #2 of this StackOverlow thread. If such a solution emerges, Iād happily add that to the aTbRef AppleScript section. As the solution to a number of āmissingā tasks is to drive menus, having a re-useable subroutine where you just feed in the current arguments (e.g. menu option label) makes a lot of sense.
A generic āhandlerā to call a menu item could be something like this:
-- call example 1: my do_menu("Tinderbox 10", "Stamps", "Turn red")
-- call example 2: my do_menu("Tinderbox 10", "Edit", "Duplicate")
on do_menu(app_name, menu_name, menu_item)
try
tell application app_name to activate --must bring to front
tell application "System Events"
tell process app_name
tell menu bar 1
tell menu bar item menu_name
tell menu menu_name
click menu item menu_item
end tell
end tell
end tell
end tell
end tell
return true
on error error_message
return false
end try
end do_menu
This seems to work for sub-menu items:
-- call example: my do_menu("Tinderbox 10", "Format", "Font", "Bold")
on do_menu(app_name, menu_name, menu_item, sub_item)
try
tell application app_name to activate --must bring to front
tell application "System Events"
tell process app_name
tell menu bar 1
tell menu bar item menu_name
tell menu menu_name
tell menu item menu_item
tell menu menu_item
click menu item sub_item
end tell
end tell
end tell
end tell
end tell
end tell
end tell
return true
on error error_message
return false
end try
end do_menu
Thanks. Iāve added a new aTbRef article: Accessing app menu items.
Site map, search index and TBX file zip are updated online.