Macro That Opens up A Directory Finder Window

Hi can anyone please help me. I am trying to think of macro that opens up a directory window finder then when I select that folder it takes that path and puts it in a variable like compressclaquette for example

Sincerely,

Keane Hubert A. Ang

This should do:


Folder Path to Variable.kmmacros (2.9 KB)


THANKS!!! This worked! :smiley:

Using System Events is not a best practice, because it leaves the user inexplicably hanging in the faceless background app – while they think they’re in the app they can see.

It’s better to explicitly use the front app:

--------------------------------------------------------------------------------
# Pick a folder and return a POSIX Path.
--------------------------------------------------------------------------------

set defaultLocation to path to desktop folder

tell application (path to frontmost application as text)
   set folderPath to POSIX path of (choose folder with prompt "Pick a Folder:" default location defaultLocation)
end tell

--------------------------------------------------------------------------------

I’ve included a default location, as an example.

The default for invisibles is false, so you don’t need it unless you deviate from the default.

Most users won’t want multiple selections allowed and show package contents.

The available syntax:

choose folder v : Choose a folder on a disk or server

   choose folder
      [with prompt text] : the prompt to be displayed in the dialog box
      [default location alias] : the default folder location
      [invisibles boolean] : Show invisible files and folders? (default is false)
      [multiple selections allowed boolean] : Allow multiple items to be selected? (default is false)
      [showing package contents boolean] : Show the contents of packages? (Packages will be treated as folders. Default is false.)
      → alias : the chosen folder

The Apple’s flat-featured Script Editor.app doesn’t have a syntax lookup function, so you have to know to open the StandardAdditions.osax with it to examine its dictionary.

Fortunately Smile (a freeware AppleScript Editor) does have a syntax-lookup function, and of course Script Debugger which I use has had such a feature for as long as I can remember.

(Script Debugger 6 is now out and reduced in price to $99.99 U.S.)

-Chris

1 Like

If you do AppleScript work, Script Debugger is a great solution.

I’m doing mostly JXA work, and I still use Script Debugger for certain tasks. Great app.

Hey Dan,

Climb on the Script Debugger forum and lobby for JXA support.

Mark is a little gun shy of this, because he released his own JavaScript scripting component about a decade ago – and it didn’t fly. (It was before its time, and he didn’t invest time in building the market back then.)

If Script Debugger 6 does well at the new price point it might happen anyway, but active lobbying can’t hurt.

-Chris

1 Like

Where do you recommend I post this support? Is there an existing topic I should reply to? I don’t want to post a new topic and have someone reply, “Hey! Ever think of searching before you post?!?”

Hey Dan,

There’s a Feature Requests category.

If you searched the SD forum for “jxa” or “javascript for automation” you wouldn’t find anything on the whole forum (I believe).

While the topic has come up before, it hasn’t on the new SD Discourse Forum.

-Chris