Getting the name of the open file in a non scriptable application

Hi all,

I’m trying to get the name of the current open file in “Nuendo 4” which is one application that doesn’t support applescript. I have no idea if this could be accomplished through “system events” or not.

All the help is very welcome.

Thanks

Does the opened file have a document window?, is the name of the file in the window title bar, or is it listed as text in some other window?

Hi Mark,

Yes. The opened file have a document window with the name of the file in the title bar.

Can not test this with your app.
But Preview.app is not scriptable

tell application "System Events"
	get name of every window of application process "Preview"
end tell

When using your code I get the following error message “System Events got an error: Access for assistive devices is disabled.”
Any ideas?

Thank you once again.

You need to go to ‘System Preferences’ → Universal Access.

Turn on Access for assistive devices (tick box at bottom)

Hey, Mark. Just wondered if you had seen this:
defaults write /Applications/Preview.app/Contents/Info NSAppleScriptEnabled -bool YES

Cheers,
Jim Neumann
BLUEFROG

Hi Jim,

I did already know about it, and have used it in the past. But since there is no Script Def dictionary for it I did do find it that much use. But Thanks anyway.

Hi Mark,

When I use the script

tell application "System Events"
	get name of every window of application process "Nuendo 4"
end tell

I get the following result: {missing value, “Nuendo Project - 017_09_tmn_guardar_v7.npr”, “VST Audio Channel Settings - ref”, “Control Room Mixer”, “Mixer”}
That correspond to the several windows opened. I can isolate the result from the window I need through

tell application "System Events"
	get name of first window of application process "Nuendo 4" whose name contains "Nuendo Project"
	
end tell

giving me the result “Nuendo Project - 017_09_tmn_guardar_v7.npr”.
Now what I need is to isolate from that result just the name of the project “017_09_tmn_guardar” (“_v7” correspond to the version of that project) so I can use it as search string in filemaker where all the data related to that project is stored. I just don’t know how to “trim” that result,
Thanks you once again.

There are many ways to skin this cat.

Using a bit of shell

tell application "System Events" to set Win_name to (do shell script "echo " & quoted form of (get name of first window of application process "Preview" whose name contains "Nuendo Project") & "|awk -F-\\  '{print $2}'")

using AppleScript’s text item delimiters

tell application "System Events"
	set Win_name to (get name of first window of application process "Preview" whose name contains "Nuendo Project")
end tell

set oldDelims to AppleScript's text item delimiters -- get normal dilm
set AppleScript's text item delimiters to {"- "} --sets new dilm Note there is a space in there.
set file_name to text item -1 of Win_name -- get the end part of  name 
set AppleScript's text item delimiters to oldDelims -- resets dilm
file_name

And so on…

Hi Mark,

That have worked wonderfully. I’ve used the text delimiters approach.

tell application "System Events"
	set Win_name to (get name of first window of application process "Preview" whose name contains "Nuendo Project")
end tell

set oldDelims to AppleScript's text item delimiters -- get normal dilm
set AppleScript's text item delimiters to {"- "} --sets new dilm Note there is a space in there.
set file_name to text item -1 of Win_name -- get the end part of  name 
set AppleScript's text item delimiters to oldDelims -- resets dilm
get file_name
set AppleScript's text item delimiters to {"."} --sets new dilm Note there is a space in there.
set ext to text item 1 of file_name -- get the end part of  name 
set AppleScript's text item delimiters to oldDelims -- resets dilm
set AppleScript's text item delimiters to {"_"}
set primeira to text item 1 of ext
set segunda to text item 2 of ext
primeira & "_" & segunda

Thank you for your help.

Another take on it.

tell application "System Events"
	set Win_name to (get name of first window of application process "Preview" whose name contains "Nuendo Project")
end tell

set oldDelims to AppleScript's text item delimiters -- get normal dilm
set AppleScript's text item delimiters to {"_"}
set file_name to (last word of text item 1 of Win_name & "_" & first word of text item 2 of Win_name)
set AppleScript's text item delimiters to oldDelims -- resets dilm
file_name --> "017_09"


And also (don’t ask how I worked this one out, a lot of trial and error) A long one liner

tell application "System Events" to tell (get name of first window of application process "Preview" whose name contains "Nuendo Project") to set Win_name to text ((my (offset of "-" in it)) + 2) thru ((my (offset of "_" in it)) + 2)
Win_name --> "017_09"

hi mark,

that last one took my breathe away! :slight_smile:

Thank you very much.