Jump to content

Create folder tree with bash

Recommended Posts

Hello, I hope my question is not yet asked somewhere else.


So, I've just created a simple and straight forward workflow to make a folder tree.


It works fine when interpreted in terminal, but in Alfred the tree is created into the workflow folder.


I've seen here that the relative path is always the path trelative to the workflow folder. My question is probably noobish but… how can get the path of the folder I'm in at the time I launch Alfred to make my request ?


Any hint would be appreciated. :)

Link to comment

You can do it with Applescript (to run applescript inside your bash script, use osascript -e "<code here>").

-- with this method
-- if a Finder window is the frontmost window, it’ll return the path to it, else it’ll return the path to the desktop

tell application "Finder" to set dirPath to (quoted form of POSIX path of (insertion location as alias))

return dirPath

-- with this method
-- if there’s any Finder window open, it’ll return the path of the frontmost one, else it’ll return the path to the home directory

	tell application "Finder" to set dirPath to (POSIX path of (folder of the front window as alias))
on error
	set dirPath to (POSIX path of (path to home folder))
end try

return dirPath
You can see this workflow for a working example.
Link to comment

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...