Saturday, October 1, 2022

#1 2022-09-07 01:19:39 am

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

Scriptable application with commands in r/o

Many properties is r/o (read only) for a scriptable application. Don't ask me why its like that
but most of whose settings could be set with GUI Scripting.

To demonstrate I made a script that make a new document with template "Blank" there document body is false (page layout). The script could be a beginning to a template for Menu Script.

Applescript:


on run
   -- Make a new document with the template "Blank"
   tell application "Pages"
       make new document with properties {document template:template "Blank"}
   end tell
   
   -- Make sure we are in document in the toolbar
   tell application "System Events" to tell process "Pages"
       set frontmost to true
       tell window 1
           tell toolbar 1 to tell group 6
               tell radio button "Document" to click
           end tell
       end tell
   end tell
   
   tell application "System Events" to tell process "Pages"
       set frontmost to true
       tell window 1
           tell splitter group 1 to tell scroll area 2
               tell checkbox 3
                   click
               end tell
           end tell
           
           -- Click the button "Convert" in the sheet.
           tell sheet 1
               tell button "Convert" to click
           end tell
       end tell
   end tell
end run

Last edited by Fredrik71 (2022-09-07 01:24:14 am)


Node-RED makes it easy to automate IoT

Offline

 

#2 2022-09-07 09:18:17 am

estockly
Member
Registered: 2009-01-03
Posts: 132

Re: Scriptable application with commands in r/o

Fredrik71 wrote:


Applescript:


   tell application "System Events" to tell process "Pages"
   



This is freaking me out. It's the second time I've seen this in the last couple days.

This script should not work.

Applescript:

tell application x to y

should not start a tell block.

This is what's used to send a single command to an application, and all the subsequent commands should not be compiling or sent to the app. (System Events, in this case).

In the other example the appleScripter was saying it was failing intermittently. I'm wondering why it doesn't fail 100% of the time.

Offline

 

#3 2022-09-07 01:48:20 pm

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

Re: Scriptable application with commands in r/o

If I understand you correctly or maybe you have never done GUI Scripting.

If you take a look in script terminology for System Events and the class Ui element
you could find element of toolbar, radio button, menu item...
To be able to script UI you need to use application "System Events" the second tell block
tell's the process... In other words if you ask for every process to return a menu item
you will get every application running... and properly not very useful.

My first post was about scripting a r/o (read only) property. In others words you couldn't
do 'set document body to false' in tell block of Pages. The reason is its r/o read only.

Last edited by Fredrik71 (2022-09-07 01:53:11 pm)


Node-RED makes it easy to automate IoT

Offline

 

#4 2022-09-07 03:11:41 pm

estockly
Member
Registered: 2009-01-03
Posts: 132

Re: Scriptable application with commands in r/o

Fredrik71 wrote:

If I understand you correctly or maybe you have never done GUI Scripting.



I've done plenty of GUI scripting. More than I would like to, but sometimes it's a last resort.

I see my mistake now.

Carry on.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)