I try to get the title of an app (and copy it as a var) Here is my code so far but this is failing
tell application "app"
activate
end tell
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
tell application frontApp
if the (count of windows) is not 0 then
set window_name to name of front window
end if
end tell
Result :
error "app got an error: every window doesn’t understand the “count” message." number -1708 from every window
The error message suggests that the frontmost application is not scriptable.
The only way to target a non-scriptable application's windows is via the properties of [application] process
objects from the System Events
context - not via its application
object (only scriptable application
objects have windows
elements):
tell application "app"
activate
end tell
tell application "System Events"
# Get the frontmost app's *process* object.
set frontAppProcess to first application process whose frontmost is true
end tell
# Tell the *process* to count its windows and return its front window's name.
tell frontAppProcess
if count of windows > 0 then
set window_name to name of front window
end if
end tell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With