The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Get The Name Of The Current Mac App In OSA/JXA JavaScript

TL;DR

Run this to get the name of the currnet app

TODO: Pull subtitle into page object
Code
#!/usr/bin/env osascript -l JavaScript

const appName = Application("System Events").processes.whose(
  {frontmost: {'=': true }}
)[0].name()

console.log(appName)
Results
iTerm2

Notes

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Get The Name Of The Current Mac App In OSA/JXA JavaScript

-- tldr/

Run this to get the name of the currnet app

-- code
-- osascript

#!/usr/bin/env osascript -l JavaScript

const appName = Application("System Events").processes.whose(
  {frontmost: {'=': true }}
)[0].name()

console.log(appName)

-- results/

iTerm2

-- /results

-- /tldr


-- notes

- When run in Emacs Org Mode the return value is blank. I'm 
guessing that has to do with the way it does the execution process

- I spent an hour figuring out that the reason I couldn't get the 
name to was due to running it in Emacs. I love having executable 
source code blocks in my grimoire, but sometimes you run into 
things like that

-- ref
-- title: JXA problem — name of application
-- url: https://forum.keyboardmaestro.com/t/jxa-problem-name-of-application/5685

-- ref
-- title: A Beginners Guide to JXA, JavaScript Application Scripting
-- url: https://computers.tutsplus.com/tutorials/a-beginners-guide-to-javascript-application-scripting-jxa--cms-27171

-- ref
-- title: Issue with the JXA Application.currentApplication() Object #27
-- url: https://github.com/johnelm/node-jxa/issues/27


-- categories
-- JXA (JavaScript For Automation)
-- Apple/OSA Script

-- metadata
-- date: 2022-10-10 12:53:40
-- id: 2fx5jh8m
-- type: post
-- site: aws
-- status: published