Jump to content

Finder scripts (including opening in a single window)


Recommended Posts

@dfay I was tinkering around with the Active Windows workflow, and I noticed that a small tweak to the "active_window.scpt" helped it start working with the OmniOutliner app.

 

Namely, if you remove the "document" reference when you're grabbing the app/name/id, it seem to work. I've copied the relevant version of the script below, commented out the original line, and added a notation to the new line in screenshot below.

 

	set theWindows to {}
	set appsForWindows to {}
	repeat with theApp in appList
		tell application theApp
			set itsWindows to every window
			repeat with w in itsWindows
				#set theWindows to theWindows & {{theApp as string, name of document of w, id of w}}
				set theWindows to theWindows & {{theApp as string, name of w, id of w}} -- Added by Jason
			end repeat
		end tell
	end repeat

 

I still haven't had any luck getting it to work with PDF Expert, but I'll keep toying with it. Do you ever use this app? Unfortunately, I suspect that it's not scriptable.

 

All the best!

Link to comment

Cool, thanks - I expect there will be a lot of similar quirks depending on how apps extend the base classes in applescript, but haven’t had the time to do further testing etc.

 

Unfortunately Readdle seems to have no interest in making their apps scriptable - I had a brief email exchange with them after PDF Expert beta for Mac launched & they’ve done nothing since.  

Edited by dfay
Link to comment

@dfay Unfortunately, my previous suggestion had the unintended side-effect of retaining the page info from Preview - which takes up a ton of space in the output (e.g., page 1 of 350, etc.). To fix this, I just added an IF/THEN statement to use the original code for Preview's windows, and the abbreviated version for other things. I don't have Skim on my machine, so I didn't add anything special for it. I suspect that you'll want to treat it like Preview (i.e., the original code)?

 

Here's the relevant portion of the "active_window" script:

 

	set theWindows to {}
	set appsForWindows to {}
	repeat with theApp in appList
		tell application theApp
			set itsWindows to every window
			repeat with w in itsWindows
				if ((theApp as string) is equal to "Preview") then -- Added by Jason
					set theWindows to theWindows & {{theApp as string, name of document of w, id of w}}
				else -- Added by Jason
					set theWindows to theWindows & {{theApp as string, name of w, id of w}} -- Added by Jason
				end if -- Added by Jason
			end repeat
		end tell
	end repeat

 

Yeah, you're definitely right about PDF Expert. I asked them about a different script-related question previously, and got brushed off. I don't think they'll ever add it. That issue seemed like it was a little more complicated than grabbing a document/window's name, however. I'm a little surprised that it doesn't work here. Isn't that limited amount required? In any case, maybe I'll have to switch to another PDF reader/annotater some day. For the most part, I use Preview. However, I've always liked the simplicity and aesthetic of PDF Expert better - so I use it when I'm reading for longer periods. Its layout for annotations and bookmarks is a lot cleaner than Preview's. I also have Adobe Acrobat Pro DC and Abby FineReader, but I'm not a big fan of these apps when just reading or taking notes.

 

I assume from the script that you're a Skim user, right? Out of curiosity, what do you do about the embedded annotations issue (assuming it's still an issue)? I never tried Skim because I hated the idea of having to remember to export each PDF after adding something to it. It's GUI always struck me as a little dated, too (but functional, nonetheless).

 

Unrelated, but were you thinking about displaying each supported app's icons in the workflow's output? I ask because I noticed the images in the workflow's folder (and think it's a good idea, too). However, they've never shown up on my computer - even before I started screwing around with it. My output just shows the generic orange four squared icon from Alfred for all windows/apps.

Link to comment

I've used Skim since 2005, before Preview added annotations, so it's largely a matter of inertia.  But it also has better AppleScript capabilities for getting notes out than anything else I've tried

 

I was trying to get the app icons but they weren't showing up despite using (what I think was) the correct json.  So I gave up and used the generic 4 square icon.

 

The "All Tags..." control would need to be addressed through GUI scripting.  I tried a bit with no success.

Link to comment
  • 2 years later...

Hi there, thanks for this awesome workflow!
 

Is there possibly a way to have all Alfred searches lead to a folder opening open in a new tab? For example, rather than typing "fo folder_or_file_name" you can just type "folder_or_file_name" and the results will open in a new tab? I rarely want more than 1 finder window open so I'm just seeing if I can kind of make this the default Alfred behavior without having to add the "fo".


Thanks either way!

Edited by davidkizler
Link to comment

Hi there, thanks for this awesome workflow!

Is there possibly a way to have all Alfred searches lead to a folder opening open in a new tab? For example, rather than typing "fo folder_or_file_name" you can just type "folder_or_file_name" and the results will open in a new tab? I rarely want more than 1 finder window open so I'm just seeing if I can kind of make this the default alfred behavior without having to add the fo.

Thanks either way! 

Link to comment
5 hours ago, davidkizler said:

Is there possibly a way to have all Alfred searches lead to a folder opening open in a new tab?


Short answer: no.

 

There's no option or API to tell Finder to open folders in a new tab. The only way to do it is to blindly fire simulated keypresses at Finder, wait a bit and tell Finder to navigate to the folder, hoping a new tab has opened in that time.

 

It's very unlikely that Andrew would add that behaviour to Alfred because it's so hacky and unreliable.

Link to comment
  • 4 months later...

I just upgraded to a Mac Studio and am running macOS 12.3. although the workflow sort of works, it now will  not find directories not at the top level of my user directory. 

 

For example, it will find /Users/tbrown/Downloads when I type "fo do", but it will not find /Users/tbrown/Downloads/irc' when I type "irc". It used to and I'm not sure when it quit. Remotely possible it is the change to Mac Studio (I had lots of problems with Migration Assistant not transferring various permissions). It could also be the upgrade to 12.3. Any suggestions? My version of the workflow is .5.

 

 

Link to comment

thanks for the tip. I fixed the problem by changing the scope of Alfred's search by dragging Macintosh HD into the scope field.

 

Now the workflow finds the directory.

 

Migration Assistant did not do me a lot of favors in this case.

Link to comment
  • 2 years later...
On 4/5/2018 at 3:20 AM, dfay said:

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

 

 

 

@dfay thanks for this wonderful workflow on Finder operations. Request to consider adding option of closing all tabs to left and right of active tab. There is one javascript code available to do this for safari tab. I tried using AppleScript and JavaScript from chatGPT but couldn't succeed in getting correct code for it. Request you to consider this request or guide.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...