dfay Posted April 4, 2018 Share Posted April 4, 2018 (edited) This is a workflow I've cobbled together from various sources, notably some modifications to https://github.com/NapoleonWils0n/bashfinder , which is actually a bash front end for a lot of AppleScript. It contains the following commands: fo - open a folder in the frontmost Finder window (also available as a File Action) fo:i - open a folder in the frontmost Finder window with Icon view (also available as a File Action) fo:c - open a folder in the frontmost Finder window with Column view (also available as a File Action) fo:l - open a folder in the frontmost Finder window with List view (also available as a File Action) all - open "All My Files" (Sierra) or "Recents" (High Sierra and later) in the frontmost Finder window - this uses a Key Combo action ⌘⇧F icloud - open iCloud Drive in the frontmost Finder window - this uses a Key Combo action ⌘⇧I fat - choose and open an existing tab or window rf - open a recent folder in the frontmost Finder window fi - set frontmost Finder window to Icon view fc - Set frontmost Finder window to Column view fl - Set frontmost Finder window to List view fg - Set frontmost Finder window to Gallery view (i.e. icon view with big icons and a dark background - this is my own take on a Gallery view, which predated the official one introduced in Mojave) fw - Close frontmost window and reopen active tab (i.e. close all tabs except the active one) merge - Merge All Windows (same as menu command) fcfix - set filename column width to 400 clip - show the Finder clipboard (I bet you didn't know there was such a thing....) There is a single environment variable: openInNewTab set it to 0 to open in the frontmost window (replacing the existing contents) or 1 (the default setting) to open in a new tab in the frontmost window By using fo and its variants, you can effectively have Alfred open folders in a single window as requested here: https://www.alfredforum.com/topic/11393-opening-folders-in-the-same-finder-window/?do=findComment&comment=59570 and here: https://www.alfredforum.com/topic/11327-any-way-search-open-a-folder-in-same-finder-window/?tab=comments#comment-59276 v.0.5 (2019-06-08) Added fat keyword (was going to use ft but it was constantly confused with FaceTime) v.0.4 (2018-08-06) Added icloud and all keywords v.0.3 (2018-04-08) Added file actions Added rf and fw keywords v.0.2 (2018-04-06) Added openInNewTab Download: https://www.dropbox.com/s/u1bchxchlm4c1q3/Finder scripts.alfredworkflow?dl=0 Edited June 9, 2019 by dfay johnnyfdot, roosterboy, brank87 and 2 others 4 1 Link to comment
gandalfsaxe Posted April 5, 2018 Share Posted April 5, 2018 Nice. Is there a way to have it open a new tab? As far as I can see `fo` always uses the last tab in the window. Link to comment
dfay Posted April 6, 2018 Author Share Posted April 6, 2018 (edited) Yes. I added an environment variable - it's set to use tabs by default since that's my preference. Adding the AppleScript to take care of the new tabs (embedded in bashfinder.sh) took all of five minutes. Trying to set the environment variable programmatically in bash took more than an hour and I gave up. So at this point you need to set it manually. Edited April 6, 2018 by dfay Link to comment
dfay Posted April 7, 2018 Author Share Posted April 7, 2018 Added file actions and rf and fg commands Link to comment
dfay Posted August 5, 2018 Author Share Posted August 5, 2018 (edited) Added all and icloud command Edited August 5, 2018 by dfay Link to comment
chezluc Posted March 5, 2019 Share Posted March 5, 2019 Thank you for this! This is amazing! Link to comment
dfay Posted March 6, 2019 Author Share Posted March 6, 2019 Thanks! Since I set this up, it's probably become my most used workflow....but I had actually forgotten about the rf command so I'm glad you got my attention to look at the docs again! Link to comment
tbrown Posted March 31, 2019 Share Posted March 31, 2019 Okay, you've got me dazzled. How in the world do I set the environment variable to avoid opening new tabs? I have set it in .profile and in my .bashrc so that it is correctly set in bash terminal windows, but this has no effect on the Alfred shortcut. It still opens new tabs. I have searched and found nothing clear about how to do this. Weird stuff like creating .plist files. What's the best way? BTW, I love this workflow. Thanks for posting it. Link to comment
deanishe Posted March 31, 2019 Share Posted March 31, 2019 1 hour ago, tbrown said: How in the world do I set the environment variable to avoid opening new tabs? https://www.alfredapp.com/help/workflows/advanced/variables/#environment Link to comment
tbrown Posted April 1, 2019 Share Posted April 1, 2019 Ha! Thanks. I didn't realize the environment variable was with Alfred. I was looking for a way to set it system wide on MacOS. No wonder I didn't find this. Works perfectly the way I want now. dfay 1 Link to comment
tbrown Posted April 2, 2019 Share Posted April 2, 2019 My use case for this workflow is usually this: I am doing something incredibly creative (!) and I need to reference a document from somewhere. I do fo (folder name) or maybe rf (select recently opened folder). The folder opens in Finder--cool! However, Finder is in the background. If I run this workflow with Finder in the background seems reasonable that I want Finder brought to the front so I can look at what I asked for. Any ideas about how to fix this in the workflow? Link to comment
deanishe Posted April 2, 2019 Share Posted April 2, 2019 Add this to the end of the relevant AppleScript: tell application "Finder" to activate Link to comment
tbrown Posted April 3, 2019 Share Posted April 3, 2019 I got this to work the way I wanted. This workflow uses bash scripts. However, one of the bash scripts adds osascript -e 'tell application "Finder" to activate' at the end to bring Finder to the front. I added this to others, like "fo" and "rf" and it works perfectly! thanks dfay 1 Link to comment
Jasondm007 Posted June 9, 2019 Share Posted June 9, 2019 @dfay Since you have a ton of great Finder workflows, I figured you'd be the right person to ask: Do you have a workflow - or know of another's workflow - that displays and searches for open Finder tabs? I often have several tabs open in the same Finder window, and am just looking for an easier way to get to the right one quickly (i.e., without having to squint to read the small print when they're smashed together). I was hoping it would operate like the many Chrome and Safari tab searching workflows that people have created. As a novice, this seems like it would be easier to accomplish in Finder than it is in Chrome or Safari - since, among other things, Finder's tabs are actually listed at the bottom of the Window menu - but what do I know! I haven't been able to find any posted to this forum or elsewhere, so perhaps it's a bit more complicated. Ha Thanks for any help you can lend! Link to comment
dfay Posted June 9, 2019 Author Share Posted June 9, 2019 2 hours ago, Jasondm007 said: Do you have a workflow - or know of another's workflow - that displays and searches for open Finder tabs? Just added one to this workflow, keyword is fat - Finder active tabs - because FT kept bringing up FaceTime. The only catch is that AppleScript treats every tab as a separate window, so if you have multiple windows, they will all appear in the results. Jasondm007 1 Link to comment
Jasondm007 Posted June 9, 2019 Share Posted June 9, 2019 @dfay You are a Finder wizard! You have saved me so much time staring at Finder windows!! I can't thank you enough. Honestly, this is great!! Link to comment
Jasondm007 Posted June 10, 2019 Share Posted June 10, 2019 @dfay After using your "Finder active tabs" script in the office for a few hours this morning, this workflow has made things so much easier for me. I just wanted to say thanks again! The script is amazing, and I really appreciate you taking the time out to create it. Link to comment
Jasondm007 Posted June 12, 2019 Share Posted June 12, 2019 (edited) @dfay By chance, do you know if your workflow for searching open Finder tabs and windows is generalizable to other apps whose menus also list their open windows or tabs? The reason I ask is because I was hoping to apply your approach to the Preview app, too. When I’m writing/researching I often have several different PDFs open in Preview - and often across more than one space/desktop and monitor (similar to the way I leave several Finder tabs open to folders that I’m working on). As a result, it’s often difficult to find the one that I’m looking for. To date, I’ve tried several different app and window switching applications (e.g., Witch, Contexts, etc.). However, they all have certain problems or quirks in this work environment. Most often, they fail to register Preview and Finder windows, which is why I reached out about Finder in the first place. I’m sure there’s no perfect solution, but since your Finder tabs workflow doesn’t seem to have any of these problems, I was hoping to do the same thing in Preview (i.e., as a separate workflow) - which has a similar approach to Finder when it comes to listing windows in its own menu. However, after duplicating your Finder Tabs workflow and slightly amending its scripts for Preview, I haven’t had any luck getting it to work. Initially, when it didn’t work, I did a little digging and found blogs complaining about Preview’s lack of AppleScript support. However, these posts were all quite old. In fact, when testing, I noticed that some of the things that they complained about actually worked just fine now (e.g., like the ability to simply close a window, etc.). Before I spend a ton more time trying research why my changes to your workflow don’t work, I was just curious if you thought your approach to Finder would also work for Preview? Thanks! Edited June 12, 2019 by Jasondm007 Link to comment
dfay Posted June 12, 2019 Author Share Posted June 12, 2019 (edited) Yeah I’m actually working on a workflow that will do this, with any app that supports Applescript including preview. Might be a week before i can get it done. Edited June 12, 2019 by dfay Jasondm007 1 Link to comment
Jasondm007 Posted June 12, 2019 Share Posted June 12, 2019 Thanks @dfay! That sounds amazing!! If there's anything I can do to help test etc., please let me know. Link to comment
dfay Posted June 19, 2019 Author Share Posted June 19, 2019 This is proving to be more complicated....getting window details is easy and standardized but what you can and can’t do with the window varies by app. Link to comment
Jasondm007 Posted June 19, 2019 Share Posted June 19, 2019 12 hours ago, dfay said: This is proving to be more complicated....getting window details is easy and standardized but what you can and can’t do with the window varies by app. @dfay I can only imagine! Do the stock MacOS apps at least use them similarly? I'm going to guess that I know the answer to that one ... 😉 If it's any consolation, selfishly, I was only hoping to use it when opening Preview windows, like Finder. However it turns out, thanks for all of your efforts! Link to comment
dfay Posted June 21, 2019 Author Share Posted June 21, 2019 (edited) Here, try this: https://www.dropbox.com/s/cn5blbpf4flq70g/Active Windows.alfredworkflow?dl=0 If you don't have Skim installed it may crash. If so, try setting the environment variable to just Preview Edited June 21, 2019 by dfay Jasondm007 1 Link to comment
Jasondm007 Posted June 21, 2019 Share Posted June 21, 2019 @dfay This is amazing!! 🤯 Thank you so much! You were right about Skim. I had to exclude it from the environment variable because it was prompting my computer to select an app for opening Skim files. I also made one small change to the "launch.scpt" file. I noticed when switching to a PDF in Preview from another desktop/space that my computer was activating Preview, but not the correct window, so I added two small lines (marked below with "NEW"). They just activate the app and add a small delay prior to opening the window. Hopefully this won't break anything, but it seems to be working just fine now. Thanks again for all of your work on this workflow! I really can't thank you enough. set theApp to (system attribute "app") set windowID to (system attribute "windowID") as integer set theDocument to (system attribute "document") set appList to words of (system attribute "appList") as list if theApp is not in appList then display alert theApp & " not configured" else -- if theApp is "Preview" then tell application theApp activate -- NEW delay 0.50 -- NEW set itsWindows to every window repeat with w in itsWindows if windowID is id of w then set index of w to 0 activate end if end repeat end tell -- end if end if Link to comment
Jasondm007 Posted June 21, 2019 Share Posted June 21, 2019 @dfay I used the workflow quite a bit today with Preview, and it's great!! Thanks a ton. I'm not sure if I introduced this problem with the code above, but the workflow doesn't always activate the appropriate pdf window in Preview. Instead, it brings it to the front, while keeping the previous one active. Have you noticed this, too? Any ideas what to change in the code above? Thanks! 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