Getting App Info With AppleScript When There's no AS Dictionary

I've been exploring using a free text editor called Moped for the specific purpose of keeping track of info on multiple Mission Control Desktops. Moped is very lightweight and it has the necessary feature of open windows reopen on the same Desktops after a reboot.

But I've hit a wall because it doesn't handle basic AppleScript. The minimal script:

tell application "Moped"
	set doc to front document
end tell

produces this error:

error "Moped got an error: Can’t get document 1." number -1728 from document 1

Unfortunately, if I can't query for the name of the window in the current desktop (if any), it's useless for my purpose.

I've gotten hints that it may be possible, notably:

Chris, @cdthomer, if you read this, any ideas? Or anyone?

Hey August, what happens if you run this AppleScript from Script Debugger?

tell application "System Events" to tell application process "Moped" to tell window 1 to return properties

Thanks, I think we're on the right track.

From Script Debugger I got:
image

and from Script Editor I got:
image

The name or title of the window I'm looking for is "[K] Keyboard Maestro ⌥⌘K .txt". It looks like I can use either name or title to access what I need, and substituting either of those for properties in your script line above, works.

Do you know of any substantial differences (or even trivial ones) between name and title in this context? From googling, it seems some apps return one, some the ot

Thanks!

I’m not aware of any operational difference between the two. I’ve researched it a few times over the years, including again last night, but found nothing. When in doubt, you could perhaps use something like the following:

tell application "System Events" to tell application process "Moped"
	tell (first window whose name is "windowName" or title is "windowTitle") to return properties
end tell

Thanks, but it's the name/title that I'm querying for. As long as I'm constantly getting the name/title as something that I can turn around and open again when I need to, and get to the file/window that I queried about in the first place, that's all I need.

FYI, not part of the original question, here's what I doing with this:

TL;dr: It's how I keep track of which desktops I've accessed, getting the name/title of the window on each desktop that names that desktop.

I'm trying Moped because it's an Open Source text editor, which means whenever I learn enough about Xcode to get it to build, then I can change the name to something meaningful to me in the context where I'm using it. What makes Moped stand out is that it's well supported, very small, and does the magical act of all open windows reopen in their original Mission Control Desktops when the system reboots.

I put a little Moped window in the botton corner of each desktop, where the name of the file is the name I want to give to that Desktop. Now that KBM, as of v11.0, has a "Space Changed" trigger, whenever the Space changes, I look for the name of the Moped (hopefully to be renamed soon) window on that Desktop. That's where the above AppleScript comes in.

I take each new Desktop name, as it comes up from the successive Space Changed triggers, and add it to the top of a variable list, deleting it wherever it previously appears in the list, a push-down stack of Desktop Space Names.

This list now allows me to have a hotkey that opens the second item on the list with Moped, which is the name of the previous Desktop I was on, which moves me to that Desktop. I also can display a Prompt With List of all the items in that list, thereby offering me the choice of all my Desktops in most-recently-used order.

And it all depends on that AppleScript above, which lets me get the name of the current Moped window after a Space Change.

I had been doing this with a clone of TextEdit (which I called DeskSpaceID.app) that I had built from the public source to TextEdit v1.9 that's available on developer.apple.com, but while my current version of TE, v1.15, also does the magic of reopening windows in their original Desktop Spaces after a reboot, v1.9 does not, much to my disappointment. So every time I reboot, I been having to recreate all the RTF windows. Even with KBM scripts, it's awkward.

Using Moped eliminates that, when I reboot, there's no additional setup before I can use all my Desktop hotkeys.

I was hugely disappointed when I thought that I couldn't get the Moped window names with AppleScript. Thanks agian, Chris @cdthomer for your help in fixing that.