Thursday, 8 June 2017

Running applescript in electron child process freezes apps on focus

I'm trying to run applescript called by osascript in electron child process to detect frontmost application name and window title. Script is being called every second via bash loop instead of applescripts loop.

Everything works fine while running unpackaged app.

The problem occurs when running packaged app, applescript execution becomes slow, and freezes the frontmost application up to 4sec on first call to the application process.

Assistive Access is turned on for packaged app.

I noticed that freeze happens when tell process fApp is being executed.

Have someone experienced something like that? What I'm doing wrong?

Mac OS X El Capitan v10.11.6

Versions

http_parser: 2.7.0
node: 7.4.0
v8: 5.6.326.50
uv: 1.10.1
zlib: 1.2.8
ares: 1.10.1-DEV
modules: 53
openssl: 1.0.2j
electron: 1.6.11
chrome: 56.0.2924.87
atom-shell: 1.6.11

Child process is being launched in main process

spawnDetached('sh', ['/path/to/bash.sh'], {
    detached: true,
    env: {
        ELECTRON_RUN_AS_NODE: 1
    }
});

Bash script

#!/bin/bash
x=-1
while(( $x != "0" ))
do
    osascript applescript.scpt
    if [ "$x" -gt "0" ]
    then
        ((x-=1))
    fi
    sleep 1
done

Applescript

#!/usr/bin/env osascript
global fApp, fTitle
tell application "System Events"
  set fApp to (name of first application process whose frontmost is true)

  tell process fApp
    set fTitle to (name of front window)
  end tell
end tell

return fApp & "," & fTitle



via Vadims Moisejenko

No comments:

Post a Comment