vitor Posted May 29, 2014 Share Posted May 29, 2014 If you regularly need to set the same files or directory structures somewhere, say a set of prebuilt scripts and template files for certain types of regular projects, this workflow is meant to make your life easier. It can take files, directory structures, and even URLs, and set them up as templates that’ll be copied over to your frontmost Finder window (if you’re using Path Finder, it will be used instead). Files and directory structures will be copied, and urls will be downloaded when requested (so you always get the latest version). To keep your templates synced between machines, use the lists_dir Workflow Environment Variable to pick a custom save location. If you have a template that consists of a directory, you can place inside it an executable script with the name starting as _templatesmanagerscript. (the extension will be your pick), to be executed automatically after copying. It has a lot of options and you’ll likely use most of them, so I’ll fire through them succinctly: Add to TemplatesManager [File Action] — Add a file or directory to your local templates. tml (TemplatesManagerList) [Script Filter] — Show a list of your local templates. Type to sort with your query. Press ↵ to copy the selected one to your frontmost Finder window. tml (with ⌘) — If the selected template is a directory, instead of copying the directory itself, copy what’s inside it. tml (with ⌥) — Delete your template. tme (TemplatesManagerEdit) [Keyword] — Open the templates directory so you can add, remove, and edit them manually. rtml (RemoteTemplatesManagerList) [Script Filter] — Show a list of your remote templates (download name and url). Type to sort with your query. Press ↵ on the selected one to download the file to your frontmost Finder window. rtml (with ⌘) — Paste contents of template file, instead of downloading it. rtml (with ⌥) — Remove the url from your remote templates list. rtme (RemoteTemplatesManagerEdit) [Keyword] — Open the remote templates urls file in a text editor so you can add, remove, and edit them manually. rtma (RemoteTemplatesManagerAdd) [Keyword] — takes the URL in your clipboard and adds it to your remote templates list. Download | Source Link to comment
vitor Posted June 3, 2014 Author Share Posted June 3, 2014 Update. As promised, you can now sort through your templates with tml and rtml (just start typing), and if you set a _templatesmanagerscript. (you pick the extension) executable script inside a template’s directory, it’ll be executed after copying. Link to comment
vitor Posted October 7, 2016 Author Share Posted October 7, 2016 Update. It now uses OneUpdater, so this should be the last time you need to manually update. Link to comment
vitor Posted November 17, 2016 Author Share Posted November 17, 2016 Update. Added option to paste remote template contents (**rtml**). Also made a number of other fixes and improvements under the hood. To update, download the latest version (same URL) or wait a few days (15 or less) and it’ll prompt you to on next usage, since it uses OneUpdater. Link to comment
mburchett2 Posted November 18, 2016 Share Posted November 18, 2016 (edited) I know you don't get a lot of feedback, but I just want to tell you how impressed I am with your work. Thank you. Edited November 18, 2016 by mburchett2 Link to comment
vitor Posted November 18, 2016 Author Share Posted November 18, 2016 Thank you, @mburchett2, I really appreciate the kind words. Link to comment
vitor Posted November 18, 2016 Author Share Posted November 18, 2016 Update. Sorting is now done by Alfred (you shouldn’t notice any difference). Also made some general code improvements and updated dependencies (again, you shouldn’t notice a difference). To update, download the latest version (same URL) or wait a few days (15 or less) and it’ll prompt you to on next usage, since it uses OneUpdater. Link to comment
boddicker Posted December 28, 2016 Share Posted December 28, 2016 Could this workflow be used to manage email templates? I find myself using a lot of the same email replies and it'd be nice to be able to save templates to a text file and pull out the text/template I need paste into an email. Link to comment
vitor Posted December 28, 2016 Author Share Posted December 28, 2016 1 hour ago, boddicker said: Could this workflow be used to manage email templates? I find myself using a lot of the same email replies and it'd be nice to be able to save templates to a text file and pull out the text/template I need paste into an email. Why not use the Snippets feature for that? Seems more appropriate. boddicker 1 Link to comment
boddicker Posted December 28, 2016 Share Posted December 28, 2016 12 hours ago, vitor said: Why not use the Snippets feature for that? Seems more appropriate. Actually...that's a brilliant idea. For some reason I never considered using snippets w/ emails. Problem solved! Link to comment
cands Posted April 14, 2017 Share Posted April 14, 2017 This is great! I just faced a task where I needed to create a large amount of folders/subfolders according to a standardized structure - solved in very short time and with no errors thanks to this handy workflow - thanks! A minor thing, it doesn't seem to work for creating folders/files when using Path Finder instead of Finder, would this be easy to fix? Link to comment
vitor Posted April 15, 2017 Author Share Posted April 15, 2017 Glad to know it worked well for you, @cands. Yes, it might be easy to make it work for Path Finder, depending on their AppleScript support. Since I haven’t used Path Finder in years, I’ll need you to perform a test. Open Path Finder in any directory. Open the Script Editor on your Mac and run this code: tell application "Path Finder" to activate tell application "System Events" to tell application "Path Finder" to return (POSIX path of (folder of the front window as alias)) What is the result? Link to comment
cands Posted April 17, 2017 Share Posted April 17, 2017 Thanks for looking into it. The result is: error "Can’t make folder of window 1 of application \"Path Finder\" into type alias." number -1700 from folder of window 1 to alias Link to comment
deanishe Posted April 17, 2017 Share Posted April 17, 2017 tell application "Path Finder" to return (POSIX path of (target of front finder window)) Link to comment
cands Posted April 17, 2017 Share Posted April 17, 2017 (edited) 5 hours ago, deanishe said: tell application "Path Finder" to return (POSIX path of (target of front finder window)) Using this tell statement the result is the full path to the currently selected folder in Path Finder. Edited April 17, 2017 by cands Link to comment
deanishe Posted April 17, 2017 Share Posted April 17, 2017 Yup. Same as the AppleScript in the workflow, except with Path Finder, not Finder. Link to comment
vitor Posted April 17, 2017 Author Share Posted April 17, 2017 Update. New icon, and added support for Path Finder (thank you @deanishe). To update, download the latest version (same URL) or wait a few days (15 or less) and it’ll prompt you to on next usage, since it uses OneUpdater. cands 1 Link to comment
raguay.customct Posted April 18, 2017 Share Posted April 18, 2017 I've found this script to work better. If you don't have the application, the above scripts will not work as well. This script doesn't stop working if you don't have one of the applications. I've also have other file managers in the list. This is what I use for my Alfred Browser workflow. on pathFinderFile() set appname to "Path Finder" tell application appname set pathfinderselection to selection if pathfinderselection is missing value then display dialog "Nothing selected" buttons {"Oh, crud..."} default button 1 return end if set pathfinderpaths to "" repeat with i from 1 to count of pathfinderselection set pfItem to item i of pathfinderselection -- Corrects for error when hidden files are showing try set currentpathfinderpath to (POSIX path of pfItem) set pathfinderpaths to pathfinderpaths & space ¬ & quoted form of currentpathfinderpath end try end repeat return currentpathfinderpath end tell end pathFinderFile on finderFile() set appname to "Finder" tell application appname try set filep to selection as alias list set finderSelection to POSIX path of filep on error display dialog "Nothing selected" buttons ¬ {"Curses, foiled again!..."} default button 1 return end try end tell return finderSelection end finderFile on commanderOneFile() set appname to "Commander One" tell application appname to activate tell application "System Events" keystroke "c" using {command down, control down} delay 0.5 end tell return the clipboard end commanderOneFile on fmanFile() set appname to "fman" tell application appname to activate tell application "System Events" key code 103 delay 0.5 end tell return the clipboard end fmanFile set fileName to "testing" set frontmostProcessName to "name" tell application "System Events" set frontmostProcess to first process where it is frontmost set frontmostProcessName to name of frontmostProcess as text end tell if frontmostProcessName is "Finder" then set fileName to finderFile() else if frontmostProcessName is "Path Finder" then set fileName to pathFinderFile() else if frontmostProcessName is "Commander One" then set fileName to commanderOneFile() else if frontmostProcessName is "fman" then set fileName to fmanFile() end if return fileName Link to comment
cands Posted April 18, 2017 Share Posted April 18, 2017 Thank you @vitor for the update! It works well with Path Finder now. vitor 1 Link to comment
vitor Posted April 18, 2017 Author Share Posted April 18, 2017 (edited) 3 hours ago, raguay.customct said: If you don't have the application, the above scripts will not work as well. Ah, of course. For a moment I forgot AppleScript is a steaming pile of garbage, and yet we need it to do things we wouldn’t be able to do otherwise (reminds me of the “small portions” joke in Annie Hall). What’s ridiculous is AppleScript has an exists that should work exactly for these cases. Yet, if the application exists it returns true, but if it doesn’t it asks you to locate it! That’s both bonkers and useless. I have an open radar (well, it’s closed as a duplicate of another one still open) asking for exists to either return false in that case, or for them to remove it. But your code is still too complex and does a lot of things I wouldn’t want to (show dialogs, emulate key presses). I’d rather just take the chance to convert it to JXA instead. It’ll keep the code lean (about the same length and same logic) and won’t suffer from the problem of needing Path Finder installed. Anyone knows how to get the path of the current Path Finder directory with JXA? For the Finder I’m doing decodeURIComponent(Application("Finder").insertionLocation().url().slice(7)). Edited April 18, 2017 by vitor Link to comment
vitor Posted April 18, 2017 Author Share Posted April 18, 2017 From this page it seems that for Path Finder decodeURIComponent will not be necessary and url().slice(7) can be replaced with posixPath(). Now it’s just a matter of knowing what insertionLocation() can be replaced with. Link to comment
deanishe Posted April 18, 2017 Share Posted April 18, 2017 return Application('Path Finder').finderWindows[0].target.posixPath() Link to comment
vitor Posted April 18, 2017 Author Share Posted April 18, 2017 Thank you again, @deanishe. Small thing: does the path end with or without a trailing /? Link to comment
vitor Posted April 19, 2017 Author Share Posted April 19, 2017 45 minutes ago, deanishe said: Without. Thank you, thought as much. The Finder JXA method is ending with (which is contrary to the AppleScript way), hence the question. 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