Reading filename into variable

I have a popup window where you select a filename and then click Open. I have a Pause until Ctrl key is pressed, so that gives me time to highlight the file I want to open. When I click the filename, I want that name to be stored in a variable.

How would you do that?

Thanks,

Jon

We need more information.
Which program creates the popup?
As @ccstone always asks. What is the complete task you try to accomplish.

The popup is really a generic question as I may use the method in multiple programs. It looks like a very standard file open, or save, window. In addition, for commercial secrets reasons I cannot reveal the specific program in this instance.

I am not sure if I have to use some Applescript or if there is a standard way to do this.

I just had a brainwave! When I select the file manually, then press Ctrl to continue my macro, could I have it do what you do when you try to rename the file. But instead of renaming it, you copy the highlighted text to the clipboard?

Hey Jon,

The specific nomenclature then would be an Open or Save dialog. People will understand that.

You cannot get the name from an item clicked in an Open dialog.

You could probably right-click on the item, select Rename, Select-All so you make sure to get the file extension, and copy to the clipboard.

I believe the only other alternative would be to use a Choose File AppleScript command to select your file and continue processing from there.

-Chris

Chris, I just posted my idea as you were posting yours! Had the same vision.

I notice on right mouse click, I am getting these options:

Move to Trash
Duplicate
Quick Look
Tags

Nothing saying rename.

Is there another way? Like click it, pause, click again? Or some key combo?

Hey Jon,

Not sure what's up with that.

All of the open dialogs in the apps I have open right now have a “Rename” item.

This must be an issue with your software.

Default Folder will let you copy the path to the clipboard.

From there it's easy to extract the name.

There are no other secret tricks that I know of.

As I said the only other thing I can think of is to use AppleScript to choose the file:

set currentApp to path to current application as text
tell application currentApp
  choose file
end tell

Run this from the Applescript Editor.app and see what it does.

From there you could probably automate your app's Open dialog.

-Chris