Jump to content

Check if selection is a folder


Recommended Posts

Posted

Howdy,

 

I want a conditional to check if my current selection in Finder is a folder or not. The only way I could come up with was checking the extension and if the result is blank, then I assume it is a folder.

 

Just wondering if there's a better way to do this?

 

image.thumb.png.f4d0a8d6ada7ca30754242ea3c8abaac.pngimage.thumb.png.bcc74c523a4cfd8d419db4a7a0399a9e.png

Posted

One way might be to use the automation task Filter Paths for Folders—which will return the path of a selected folder but nothing if a file, instead of a folder, is selected.

 

Stephen

Posted (edited)
19 hours ago, Floating.Point said:

Just wondering if there's a better way to do this?

 

Checking for an extension isn’t reliable because files can be extensionless. @Stephen_C’s solution is clever and should work, but I’ll add proper checks for “Is File?” and “Is Folder?” for the next Automation Tasks release.

 

In the meantime, you can use a Run Script with default settings and code: [[ -d "${1}" ]] && echo -n 'true' || echo -n 'false'. That will be true if a folder and false if not.

 

Edited by vitor

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...