Apple Intelligence is now available on iPhone, iPad, and Mac!

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Shortcut go to folder containing the file opened in TextEdit

Hi all,

I know that I could right click on the window title to have the folder path but the question is specifically to use a keyboard shortcut.

Maybe is there a way through the creation of an Automator service? Or AppleScript?

Any suggestions are accepted thanks :)




Posted on Mar 25, 2020 3:01 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 25, 2020 4:06 PM

It can be done with AppleScript and an Automator Service/Quick Action that asks Finder to open the current TextEdit file's folder window.


From the Dock, click Launchpad : Other : Automator. Select Desktop in the sidebar of the dialog it launches, and then click New Document. Select either Service, or Quick Action depending on your version of macOS, and click Choose.


In the left panel, there will be a number of libraries that offer Automator actions. Select Utilities, and click, drag, and drop the Run AppleScript action right-ward into the larger workflow window. Select the line in the Run AppleScript boiler plate:


(* Your script goes here *)


And then copy/paste the following AppleScript code so that it replaces that selected line, and nothing else:


tell application "TextEdit"
	tell front document
		set apath to (its path) as text
	end tell
end tell

tell application "Finder"
	set cfold to item (apath as POSIX file)'s container
	open cfold's container window
end tell


When you have finished this copy/paste, the Run AppleScript window contents will look like this:



You also have to configure the top part of this Automator solution, and here is the whole Service/Quick Action, including how the top part of it should be set.



Click File menu : Save… and name it something intuitive (e.g. Show TextEdit File Container, etc.) and then quit Automator.


In System Preferences : Keyboard : Shortcuts : Services, scroll down in that window until you encounter the name given to the Automator service. It will already be activated, but keyboard shortcuts are entered at the right by clickong on the word none, which will be replaced by Add Shortcut, and another click I entered control-F which echoes as ^F in this window. Press return to set it.


In TextEdit, with a file open, visit TextEdit : Services : and select the name given to this Automator service. A small dialog will appear about the Automator wanting to control Finder. Click Ok, and the FInder will open a window of the files folder. From this point on, you can be in TextEdit and press control-F (or your shortcut), and the Finder window will immediately appear.



Similar questions

4 replies
Question marked as Top-ranking reply

Mar 25, 2020 4:06 PM in response to mcflay

It can be done with AppleScript and an Automator Service/Quick Action that asks Finder to open the current TextEdit file's folder window.


From the Dock, click Launchpad : Other : Automator. Select Desktop in the sidebar of the dialog it launches, and then click New Document. Select either Service, or Quick Action depending on your version of macOS, and click Choose.


In the left panel, there will be a number of libraries that offer Automator actions. Select Utilities, and click, drag, and drop the Run AppleScript action right-ward into the larger workflow window. Select the line in the Run AppleScript boiler plate:


(* Your script goes here *)


And then copy/paste the following AppleScript code so that it replaces that selected line, and nothing else:


tell application "TextEdit"
	tell front document
		set apath to (its path) as text
	end tell
end tell

tell application "Finder"
	set cfold to item (apath as POSIX file)'s container
	open cfold's container window
end tell


When you have finished this copy/paste, the Run AppleScript window contents will look like this:



You also have to configure the top part of this Automator solution, and here is the whole Service/Quick Action, including how the top part of it should be set.



Click File menu : Save… and name it something intuitive (e.g. Show TextEdit File Container, etc.) and then quit Automator.


In System Preferences : Keyboard : Shortcuts : Services, scroll down in that window until you encounter the name given to the Automator service. It will already be activated, but keyboard shortcuts are entered at the right by clickong on the word none, which will be replaced by Add Shortcut, and another click I entered control-F which echoes as ^F in this window. Press return to set it.


In TextEdit, with a file open, visit TextEdit : Services : and select the name given to this Automator service. A small dialog will appear about the Automator wanting to control Finder. Click Ok, and the FInder will open a window of the files folder. From this point on, you can be in TextEdit and press control-F (or your shortcut), and the Finder window will immediately appear.



Mar 27, 2020 3:29 PM in response to VikingOSX

Very thanks VikingOSX for the clarity and completeness of your answer!

In the beginning I was looking for a solution through bash but using AppleScript is really the best solution.

I didn't know it could be so useful.

So I studied the syntax a bit and here it is another version of the code in order to make Finder the window in the foreground:


tell application "TextEdit"
	tell front document
		set apath to (its path) as text
		tell application "Finder" to open item (apath as POSIX file)'s container's container window
	end tell
end tell

tell application "Finder"
	activate
end tell


return

Mar 27, 2020 3:36 PM in response to mcflay

Instead if you want to run a bash script based on the file currently open with TextEdit here is a slightly different version:



tell application "TextEdit"
	tell front document
		set filePath to (its path) as text
	end tellend tell

do shell script "/Users/developer/<insert_your_path>/Script\\ Bash/bash_script.sh " & quoted form of filePath



which becomes very very useful when you set a keyboard shortcut!

Shortcut go to folder containing the file opened in TextEdit

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.