Phaks Posted April 13, 2021 Share Posted April 13, 2021 Hey, first of all, thanks for the useful workflow! Is there a way to create a folder (or multiple folders at once)? Many thanks, Phaks Link to comment
vitor Posted April 14, 2021 Author Share Posted April 14, 2021 23 hours ago, Phaks said: Is there a way to create a folder (or multiple folders at once)? Yes, that’s pretty easy to do but I don’t see the point of adding that to this Workflow when you can just ⌘⇧N and start typing to make a new directory. Adding that to the Workflow wouldn’t save any work. Link to comment
Phaks Posted April 14, 2021 Share Posted April 14, 2021 2 hours ago, vitor said: Adding that to the Workflow wouldn’t save any work. I would personally used it for creating multiple folders at once. Currently I'm using this command in Terminal to do so: mkdir 'folder01' 'folder02' 'folder03' - but being able to execute it within Alfred would be great. Link to comment
vitor Posted April 18, 2021 Author Share Posted April 18, 2021 @Phaks On the Run Script, edit the touch "${file_location}" line (near the end) to be mkdir "${file_location}", and delete the [[ -z "${file_extension}" ]] && file_extension=".txt" line (a few above). That’ll do what you want, and it’s the extent to which I will support that feature. Link to comment
mjp Posted April 25, 2021 Share Posted April 25, 2021 @Phaks I use the following code: dir_path="$(osascript -l JavaScript -e ' const frontmost_app_name = Application("System Events").applicationProcesses.where({ frontmost: true }).name()[0] if (frontmost_app_name === "Finder") { decodeURIComponent(Application("Finder").insertionLocation().url()).slice(7).slice(0, -1) } else if(frontmost_app_name === "Path Finder") { decodeURIComponent(Application("Path Finder").finderWindows[0].target.url()).slice(7).slice(0, -1) } else { decodeURIComponent(Application("Finder").desktop.url()).slice(7).slice(0, -1) } ')" IFS=$'/\n' for dir in ${@}; do dir_location="${dir_path}/${dir}" mkdir "${dir_location}" if [[ "${open_dirs}" == 'yes' ]]; then open "${dir_location}"; fi done Note that I also changed the variable names in the Arg and vars utilities from open_files to open_dirs. Will later look into enabling syntax that directories can be created using native mkdir syntax such as (nd is the Alfred command for creating the new directories): nd Dir1 'Dir 2' "Dir 3" Dir{4,5,6} Dir{7..100} to create below directories in current foremost directory: Dir1 Dir 2 Dir 3 Dir 4 Dir 5 Dir 6 Dir 7 ... Dir 100 Phaks 1 Link to comment
mjp Posted April 25, 2021 Share Posted April 25, 2021 (edited) 1. Copy workflow NewFile and rename copy to NewDir 2. Change keywords nf to nd and nfo to ndo in NewDir 3. Change variable open_file to open_dirs in the two Args and vars utilities. 4. Edit the Run script action, change the with input as argv to with input as {query}, and running instances should be Sequentially, and then replace the Script with below: # ----------------------------------------------------------------------------- # CREDITS: # - Step 1 and partially Step 3 is based on Vítor Galvão:s NewFile workflow # NOTES: # - This is just a simple wrapper around the built-in macOS bash-shell and mkdir command. # - To use spaces in directory names, use quotes (single and double work): "Dir 1", 'Dir 1', "Dir 1-"{1..3}, 'Dir 2-'{1..3} etc. # - This uses spaces as argument delimiters, change Step 2 below if you want to use another delimiter # USE EXAMPLES: # - nd dir1 # - nd dir1 dir2 # - nd 'dir 1' # - nd "dir 1" # - nd 'dir 1' 'dir 2' # - nd 'dir '{1..10} # - nd "dir "{1..10} # - nd 'dir 1-'{1..10} 'dir 2-'{1..10} # - nd "dir 1-"{1..10} "dir 2-"{1..10} # - nd 'dir 1' 'dir 2' 'dir 3' 'dir {4,5,10}' 'dir '{10..100} # - nd 'dir 1' 'dir 2' 'dir 3-'{1..3} 'dir 4-'{1..3} # - nd dir{1..10}/subdir{1..10} # - nd 'dir '{1..10}/'subdir '{1..10} # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # Step 1. Set pwd/dir_path to that of frontmost app dir_path="$(osascript -l JavaScript -e ' const frontmost_app_name = Application("System Events").applicationProcesses.where({ frontmost: true }).name()[0] if (frontmost_app_name === "Finder") { decodeURIComponent(Application("Finder").insertionLocation().url()).slice(7).slice(0, -1) } else if(frontmost_app_name === "Path Finder") { decodeURIComponent(Application("Path Finder").finderWindows[0].target.url()).slice(7).slice(0, -1) } else { decodeURIComponent(Application("Finder").desktop.url()).slice(7).slice(0, -1) } ')" # ----------------------------------------------------------------------------- # Step 2. Set spaces as delimiters for arguments IFS=$' ' # ----------------------------------------------------------------------------- # Step 3. for each arg, create dir(s), and if ndo command: open them afterwards for dir in {query}; do # set new dir loc according to frontmost app new_dir_loc="${dir_path}/${dir}" # create new dir(s) according to arguments mkdir -p "${new_dir_loc}" # if using ndo command, then open newly created dir(s) afterwards if [[ "${open_dirs}" == 'yes' ]]; then open "${new_dir_loc}"; fi done # ----------------------------------------------------------------------------- The above works for simple Alfred commands such as: nd dir to create dir named dir in foremost dir. nd dir{1,2,3} to create dirs named dir1,dir2,dir3 in foremost dir. nd dir{1..3} to create dirs named dir1,dir2,dir3 in foremost dir. nd dir{1..3} dir{5..8} to create dirs named dir1,dir2,dir3,dir5,dir6,dir7,dir8 in foremost dir. nd dir{1..3}/dir{1..3} to create dirs dir1, dir2, dir3, dir1/dir1, dir1/dir2, dir1/dir3, dir2/dir1, dir2/dir2 etc. starting from foremost dir. etc. Edited April 25, 2021 by mjp Link to comment
deanishe Posted April 25, 2021 Share Posted April 25, 2021 18 minutes ago, mjp said: Copy workflow NewFile and rename copy to NewDir If I were you, I'd release that workflow (and create a new thread for it). It looks really useful, and a lot of people don't really have the skills to easily modify an existing workflow. Your post is also likely not to age well, as the NewFile workflow might look very different in five years' time (when people will still be finding your post and wanting to have the workflow). Link to comment
mjp Posted April 25, 2021 Share Posted April 25, 2021 @deanishe: I will consider that. Haven't read about best practice regarding releasing workflows yet, as I just spent some minutes hacking it together. Will read up on it and release it. But it feels somewhat banal as I just hacked it together borrowing the most interesting parts from @vitor's NewFile. I feel it (or a better version of it) would do better as part of @vitor:s already excellent set of workflows which has more audience attraction and better chance of reaching those users that might have use for it. But if @vitor doesn't mind, I can look into releasing it as a separate one. Will give credit to @vitor of course. vitor 1 Link to comment
vitor Posted April 25, 2021 Author Share Posted April 25, 2021 4 hours ago, mjp said: using native mkdir syntax The examples you posted are handled by the shell, not mkdir. That is to say, “mkdir syntax” doesn’t exist. But what you want is pretty easy to implement: change the Run Script from with input as argv to with input as {query} and just have it mkdir {query}. However, I’ll recommend against that because it means you then have to write all your names with a shell’s syntax and care. By that point, might as well use RunCommand; doing it in NewFile would be duplication of functionality. I still don’t see much point in it, but if someone wants it enough to modify it to that extent, I’ll consider it. Though for file creation I settled on / as the separator because it isn’t used in names, but in directories that could be valid for subdirectories. I may change the separator to |. Though I probably still won’t add the shell creation features because I don’t want people to shoot themselves in the foot by mistake; complex behaviour should be handled by RunCommand. I’ll probably also change the Workflow’s name to NewPath, though you don’t have to worry about that as OneUpdater will take care of it. Link to comment
vitor Posted April 25, 2021 Author Share Posted April 25, 2021 Updated it to NewPath, with support for both files and directories. See the top post for the new way of handling it. You can download it now or wait for the auto-update to kick in. Phaks 1 Link to comment
Chq Posted May 8, 2021 Share Posted May 8, 2021 Amazing workflow (including folder(-s) creation). Thank you so much. Greetz Chris Link to comment
vitor Posted May 9, 2021 Author Share Posted May 9, 2021 17 hours ago, Chq said: including folder(-s) creation Quite the popular feature, I see! Had I known earlier, I’d have added it sooner. You can thank @Phaks and @mjp for the push to do it. Link to comment
Chq Posted May 9, 2021 Share Posted May 9, 2021 I added a hotkey for generating an often used txt-file of mine (see picture). Is it possibility to add the hotkey so, that it is not necessary to press "enter", after triggering? Greetz Chris Link to comment
vitor Posted May 9, 2021 Author Share Posted May 9, 2021 10 hours ago, Chq said: Is it possibility to add the hotkey so, that it is not necessary to press "enter", after triggering? Don’t connect it to the Hotkey, connect it to the Argument and Variables Utility. Chq 1 Link to comment
Pseud0nymer Posted July 4, 2021 Share Posted July 4, 2021 Sorry to find that this workflow failed to create .xlsx files. Did I make any mistakes when performing the action? Thank you! Link to comment
deanishe Posted July 4, 2021 Share Posted July 4, 2021 7 minutes ago, Pseud0nymer said: Sorry to find that this workflow failed to create .xlsx files. Did I make any mistakes when performing the action? Thank you! What does the dialog say? Very few forum members understand Chinese. Link to comment
vitor Posted July 4, 2021 Author Share Posted July 4, 2021 The Workflow just creates empty files with the appropriate extension. Some file types, even when “empty”, have a specific structure. That’s not something I want to support, I don’t intend to ship a file of each with the Workflow for a narrow use case. Link to comment
deanishe Posted July 4, 2021 Share Posted July 4, 2021 3 hours ago, vitor said: I don’t intend to ship a file of each with the Workflow for a narrow use case. How about creating a templates directory in the workflow’s data directory where users can put their own empty (or not) files? Then if there’s a file in there with the same extension as the new file the user’s creating, copy that instead of just touching a file? vitor 1 Link to comment
vitor Posted July 5, 2021 Author Share Posted July 5, 2021 On 7/4/2021 at 12:22 PM, deanishe said: How about creating a templates directory in the workflow’s data directory where users can put their own Nice idea. Won’t commit to it just yet because I’m having some busy days, but I’m not at all opposed to it. On 7/4/2021 at 12:22 PM, deanishe said: empty (or not) files For the “or not” case, there’s TemplatesManager. Link to comment
shamster Posted July 16, 2021 Share Posted July 16, 2021 @vitor Just wanted to say this is awesome and thank you for this. I really appreciate it. vitor 1 Link to comment
Craigers Posted July 25, 2022 Share Posted July 25, 2022 Thanks for this workflow vitor. Most helpful. Link to comment
sepulchra Posted October 25, 2022 Share Posted October 25, 2022 @vitor I just found this great workflow. One thing I am running into. When I create a new path with your workflow and later try to use my universal action hotkey it perceives that folder as text and only provides me with text actions. Any folder created in the finder itself that is sent to alfred with the universal action hotkey is perceived as a file and provides more options. If i go into the finder and rename the folder that was created with your workflow and then use the universal action hotkey alfred presents the file options. Any reason why alfred is thinking folders created with your workflow are just text? Can you recreate? I'm on 12.6. Link to comment
vitor Posted October 25, 2022 Author Share Posted October 25, 2022 Not only can’t I reproduce, that’s not something I remember seeing. Link to comment
sepulchra Posted October 25, 2022 Share Posted October 25, 2022 when in doubt restart. apologies for having wasted your time. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now