Jump to content

mjp

Member
  • Posts

    7
  • Joined

  • Last visited

mjp's Achievements

Helping Hand

Helping Hand (3/5)

2

Reputation

  1. @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.
  2. 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.
  3. @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
  4. Big thanks @deanishe! That solved it! It is also somewhat more elegant/minimalistic in a way than I first had in mind! But is there any particularly good reason why it is not possible to do it by direct links as I first imagined? I imagine that direct linking would visualize the flow better (assuming that the flow is not super large and messy).
  5. Hi all, Do you know if it is possible to traverse back in a workflow using list filters? An example workflow of what I had in mind: Example workflow: https://drive.google.com/file/d/19BDuKH_f14yvBFZld70FOMT7r9_XFY-3/view?usp=sharing Currently I am unable to link the junction output back to any object in the workflow. What I am trying to do is link the "back" outputs from "fork2" and "fork3" objects back to the "Arg and Vars" object input before "fork1".
  6. Wow, big thanks for the incredibly fast reply and fix. Confirming that it works now also with paths containing hash signs. Keep up the amazing work!
  7. I noticed that this workflow does not create new files when the path contains a directory name containing a hash (#) sign.
×
×
  • Create New...