Created
October 17, 2014 23:42
-
-
Save Noitidart/8b875261d1a9dbd6b0cf to your computer and use it in GitHub Desktop.
_applescript-FocusMostRecentWindow -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "System Events" to tell application process "Firefox" | |
tell application "Firefox" | |
activate | |
tell windows | |
set minimized to false | |
set visible to true | |
end tell | |
end tell | |
end tell |
tell application "System Events"
set theprocs to every process whose unix id is 164
repeat with proc in theprocs
set the frontmost of proc to true
exit repeat
end repeat
end tell
This above works but can be simplified.
Given that by definition only one process can match -- PIDs (process IDs) uniquely identify a single process -- there is no need for a loop: simply directly target the first (and by definition only) element of the list of PIDs returned by the filter process whose unix id is ...
# Note: Assumes that variable `myProcessId` contains the PID of interest.
tell application "System Events"
set frontmost of the first process whose unix id is myProcessId to true
end tell
can run via popen from addon:
Cu.import('resource://gre/modules/ctypes.jsm');
function doit() {
_x11 = ctypes.open('libc.dylib');
var popen = _x11.declare('popen', ctypes.default_abi, ctypes.voidptr_t, // Return int
ctypes.char.ptr, // Param1 const char *command
ctypes.char.ptr // Param1 const char *command
);
var fread = _x11.declare('fread', ctypes.default_abi, ctypes.size_t, // Return int
ctypes.voidptr_t,
ctypes.size_t,
ctypes.size_t,
ctypes.voidptr_t
);
var pclose = _x11.declare('pclose', ctypes.default_abi, ctypes.int, // Return int
ctypes.voidptr_t
);
////////////////////////
////END DECLARATIONS
////////////////////////
var file = popen('osascript -e \'tell application "System Events" to set frontmost of the first process whose unix id is 727 to true\'', 'r')
console.log(file.toString())
pclose(file);
}
console.time('popen');
doit();
console.timeEnd('popen')
This popen
does AXRaise
and it does it as System Events
Cu.import('resource://gre/modules/ctypes.jsm');
function doit() {
_x11 = ctypes.open('libc.dylib');
var popen = _x11.declare('popen', ctypes.default_abi, ctypes.voidptr_t, // Return int
ctypes.char.ptr, // Param1 const char *command
ctypes.char.ptr // Param1 const char *command
);
var fread = _x11.declare('fread', ctypes.default_abi, ctypes.size_t, // Return int
ctypes.voidptr_t,
ctypes.size_t,
ctypes.size_t,
ctypes.voidptr_t
);
var pclose = _x11.declare('pclose', ctypes.default_abi, ctypes.int, // Return int
ctypes.voidptr_t
);
////////////////////////
////END DECLARATIONS
////////////////////////
var file = popen('osascript -e \'tell application "System Events" to tell first process whose unix id is 398 \n set frontmost to true \n \n perform action "AXRaise" \n end tell\'', 'r')
console.log(file.toString())
pclose(file);
}
console.time('popen');
doit();
console.timeEnd('popen')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
README
Rev1
He mentions some unpredicatability with this, but notes that it is Assitive-less Window Raising: