Saturday, December 16, 2017

#1 2016-09-18 09:35:55 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3203

When Pages become Script Editor

Hello

In a script supposed to treat thousands of documents with Pages and LibreOffice, every 20 messages, I decided to clear the list of recent items in LibreOffice, quit Pages and LibreOffice then restart them to reduce memory use.

It works well but when I looked at the Events log I saw some surprising lines.

The code is :

Applescript:

# Quitte les deux applications pour leur faire libérer la mémoire occupée
tell application id "com.apple.iWork.Pages" to quit
tell application "LibreOffice" to quit
# Relance les applications pour qu'elles soient disponibles pour lr document suivant.
tell application id "com.apple.iWork.Pages" to activate
tell application "LibreOffice" to activate

I trigger Pages via its application id so that the script doesn't change according to the version in use which may be Pages v.4.x or v.5.x

In the log the tasks are reported as :

tell application "Script Editor" # was supposed to be "Pages"
    quit
end tell
tell application "LibreOffice"
    quit
        --> error number 0 # non fatal error
end tell
tell application "Script Editor" # What is it doing here ?
    activate
end tell
tell application "Pages"
    activate
end tell
tell application "Script Editor" # What is it doing here ?
    activate
end tell
tell application "LibreOffice"
    activate
end tell

I would be interested if somebody may give an explanation to this behavior.



Yvan KOENIG running El Capitan 10.11.6 in French (VALLAURIS, France) dimanche 18 septembre 2016 16:35:09

Offline

 

#2 2016-09-18 06:52:58 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: When Pages become Script Editor

I suspect you need to add some delay after quitting the apps. It looks like the target application is not being found, and the commands are therefore falling through to the current application (Script Editor).


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2016-09-19 02:00:44 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3203

Re: When Pages become Script Editor

Hello Shane

The instruction :

tell application id "com.apple.iWork.Pages" to quit

is reported as :

tell application "Script Editor" # was supposed to be "Pages"
    quit
end tell

although it's the first one to be executed - after a lot of other tasks.
In the real script there are also numerous tasks between the two 'qui' and the two 'activate'.
The job is perfectly done but I don't understand why the log reports Script Editor.

After posting my question, I discovered that

Applescript:

# Quitte les deux applications pour leur faire libérer la mémoire occupée
tell application "Pages" to quit
tell application "LibreOffice" to quit
delay 1
# Relance les applications pour qu'elles soient disponibles pour lr document suivant.
tell application "Pages" to activate
tell application "LibreOffice" to activate

is reported as :

tell application "Pages" # this time it's Pages
    quit
end tell
tell application "LibreOffice"
    quit
end tell
tell application "Script Editor" # this one is always puzzling
    activate
end tell
tell application "Pages"
    activate
end tell
tell application "Script Editor" # this one is always puzzling
    activate
end tell
tell application "LibreOffice"
    activate
end tell

in the events log.

If I code :

Applescript:

quit application "Pages"
quit application "LibreOffice"
delay 1
# Relance les applications pour qu'elles soient disponibles pour lr document suivant.
activate application "Pages"
activate application "LibreOffice"

or

Applescript:

quit application id "com.apple.iWork.Pages"
quit application "LibreOffice"
delay 1
# Relance les applications pour qu'elles soient disponibles pour lr document suivant.
activate application id "com.apple.iWork.Pages"
activate application "LibreOffice"

I retreive :

tell application "Script Editor"
    quit
end tell
tell application "LibreOffice"
    quit
end tell
tell application "Script Editor"
    activate
end tell
tell application "Pages"
    activate
end tell
tell application "Script Editor"
    activate
end tell
tell application "LibreOffice"
    activate
end tell

Same behavior if I replace application "LibreOffice" by application id  "org.libreoffice.script"


Yvan KOENIG running El Capitan 10.11.6 in French (VALLAURIS, France) lundi 19 septembre 2016 09:00:24

Offline

 

#4 2016-09-19 04:03:16 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4456

Re: When Pages become Script Editor

I get similar logs when substituting Numbers for LibreOffice in Yvan's script immediately above.

The "Script Editor" business only appears when there's communication with another application in between the 'quit' and 'activate' commands:

Applescript:

-- With Pages and Numbers both already open:
tell application "Pages" to quit
tell application "Numbers" to get window 1
delay 1
tell application "Pages" to activate

(* Event log:
tell application "Pages"
   quit
end tell
tell application "Numbers"
   get window 1
end tell
tell application "Script Editor"
   activate
end tell
tell application "Pages"
   activate
end tell
*)

When there's no intervening communication:

Applescript:

tell application "Pages" to quit
--tell application "Numbers" to get window 1
delay 1
tell application "Pages" to activate

(* Event log:
tell application "Pages"
   quit
   activate
end tell
tell application "Pages"
   activate
end tell
*)

… which is equally interesting. It seems to be a harmless Script Editor logging quirk. Nothing to do with the targeted applications.


NG

Online

 

#5 2016-09-19 07:21:50 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: When Pages become Script Editor

Running it in ASObjC Explorer or Script Debugger gives you more clue what's going on. Script Debugger gives the best view.

So in Nigel's first script, you can see that Pages gets told to quit, then Numbers gets asked for window 1. Then when Pages is told to activate, the log shows the result as:

Applescript:

no eligible process with specified descriptor (procNotFound:-600)

In other words, AppleScript tries to prepare an event to send to what AppleScript assumes is still the Pages process, but which is no longer running. AppleScript must somehow recognize this error, and treats it as a signal to abort sending the event and instead construct a new event containing a proper target, and to send that. That results in a second activate in both logs.

The reason Script Editor shows itself as target of the first activate is that when it finds no target in an event, it falls back to itself as the default target in order to get proper source to include in the log. If it did not, other stuff would not be logged correctly. And Explorer does the same thing.

In Explorer's case, the error is also logged but by number only:

Applescript:

-->    error number -600

Look that up in MacErrors and it says no eligible process with specified descriptor.

Script Editor is not logging the error. It looks like it only logs errors generated from replies to events, and ignores the (relatively rare) errors generated in constructing outgoing events.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#6 2016-09-19 07:27:47 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3203

Re: When Pages become Script Editor

Thanks Nigel

Your message pushed me to make other tests with other applications giving funny results.

Applescript:

tell application "Mail" to quit
tell application "TextEdit" to quit
delay 1
tell application "Mail" to activate
tell application "TextEdit" to activate

give :

tell application "Mail"
    quit
        --> error number 0 # non fatal one
end tell
tell application "Script Editor"
    quit
end tell
tell application "Script Editor"
    activate
end tell
tell application "Mail"
    activate
end tell
tell application "Script Editor"
    activate
end tell
tell application "TextEdit"
    activate
end tell

Then I changed the order of the applications :

Applescript:

tell application "TextEdit" to quit
tell application "Mail" to quit
delay 1
tell application "TextEdit" to activate
tell application "Mail" to activate

tell application "Script Editor"
    quit
end tell
tell application "Mail"
    quit
end tell
tell application "Script Editor"
    activate
end tell
tell application "TextEdit"
    activate
end tell
tell application "Script Editor"
    activate
end tell
tell application "Mail"
    activate
end tell

When I ran the 1st version in Shane's ASObjC Explorer, I got :

14:20:10,925 tell application "Mail" to quit
14:20:11,242 [1] tell application "Mail" to quit
14:20:11,244 tell application "TextEdit" to quit
14:20:11,245 [2] tell application "TextEdit" to quit
14:20:12,246 [3] delay 1
14:20:12,248 tell application "ASObjC Explorer 4" to activate
  -->    error number -600
14:20:13,493 tell application "Mail" to activate
14:20:13,626 [4] tell application "Mail" to activate
14:20:13,628 tell application "ASObjC Explorer 4" to activate
  -->    error number -600
14:20:14,040 tell application "TextEdit" to activate
14:20:14,145 [5] tell application "TextEdit" to activate

With the 2nd one in Shane's ASObjC Explorer I got :

14:22:58,539 tell application "TextEdit" to quit
14:22:58,556 [1] tell application "TextEdit" to quit
14:22:59,240 tell application "Mail" to quit
14:22:59,241 [2] tell application "Mail" to quit
14:23:00,242 [3] delay 1
14:23:00,242 tell application "ASObjC Explorer 4" to activate
  -->    error number -600
14:23:00,578 tell application "TextEdit" to activate
14:23:00,680 [4] tell application "TextEdit" to activate
14:23:00,681 tell application "ASObjC Explorer 4" to activate
  -->    error number -600
14:23:01,926 tell application "Mail" to activate
14:23:02,042 [5] tell application "Mail" to activate

So, I guess that the problem isn't in the Editor but in AppleScript itself.

Maybe Shane will find what is playing the fool wink

Yvan KOENIG running El Capitan 10.11.6 in French (VALLAURIS, France) lundi 19 septembre 2016 14:25:22

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)