Jump to content
Vivien

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

Share this post


Link to post

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

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

Share this post


Link to post

Thanks a lot Vítor. It works perfectly.

 

I didn't want to use applescript because my last workflow used it and it was a pain, but since it seems I have no choice… :-)

 

Thanks again.

Share this post


Link to post

I didn't want to use applescript because my last workflow used it and it was a pain.

I know the feeling — a mix between “I hate this” and “at least there’s some way to do it”.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...