当您创建文件或将文件复制到Mac时,会为其分配一个路径,该路径是文件在Mac上的实际位置。路径(Paths)可让您轻松访问计算机上的任何文件夹或文件,因为它们代表保存在计算机上的文件的完整地址。
有时,出于各种原因,您可能希望在Mac上显示文件的路径。(Mac)也许您正在编写一个将文件路径作为输入的程序。或者,您可能已经在Mac上安装了一个应用程序,它会要求您输入文件的路径。
无论(Regardless)您为什么要显示文件的路径,在您的机器上都有几种方法可以这样做。macOS 内置了许多选项,可帮助您查看甚至复制保存在计算机上的任何文件的完整路径。
如果这对您来说还不够简单,您甚至可以创建自己的Automator服务,只需单击一下即可复制所选文件的路径。
此外,请随时从我们的姊妹网站查看我们的 YouTube 频道,我们会在短视频(short video)中介绍不同的方法。
(Reveal File Paths)使用信息框(Info Box)显示文件路径
如果您已经使用Mac一段时间了,您可能已经看到右键单击文件时出现的“获取信息”选项。(Get Info)
此选项会打开一个框,其中会显示有关您的文件的所有信息。这些信息包括文件名、文件类型、文件大小和最重要的一个——文件路径。
要亲自查看,请打开Finder窗口,右键单击任何文件,然后选择Get Info。
在以下屏幕上,查找标有Where的标签,您将在Mac上看到所选文件的完整路径。它显示您的文件所在的文件夹和嵌套文件夹。
虽然它可以很好地帮助您找到文件的路径,但如果您想要这样做,它不会让您将文件路径复制为纯文本。如果要将文件的路径复制到剪贴板,您可能需要查看下面提到的其他一些方法。
(Copy File Paths)从上下文菜单(Context Menu)复制文件路径
Mac上的上下文菜单是一个非常强大的工具,因为它可以让您对文件执行更多操作,而不仅仅是重命名或删除文件(it lets you do much more with your files than just letting you rename or delete your files)。
上下文菜单中有用且隐藏的选项之一可让您直接将文件路径复制到剪贴板。
由于默认情况下它是隐藏的,因此当您右键单击Mac(Mac)上的文件时它不会出现。但是,取消隐藏选项非常简单,只需按住Option键即可。这将使该选项在您的上下文菜单中可见。
要使用该选项,请右键单击Finder中的文件,按住键盘上的
Option键,您将看到Copy “file-name.ext” as Pathname选项。单击(Click)它以复制文件的路径。
它会将您选择的文件的路径作为纯文本复制到剪贴板。
使用 Finder 查看文件路径
你可能会想,如果Finder是一个文件管理应用程序,那它为什么不提供复制文件路径的功能呢?不幸的是,当前版本的Finder没有复制文件路径的可见选项。
但是,这并不意味着真的没有办法使用Finder查看文件路径。确实有一个功能 - 不是为显示文件路径而构建的 - 但可以帮助您查看计算机上的文件路径。
它被称为“转到文件夹(Go to Folder)”功能,它实际上是为了帮助您转到Mac上的某个位置。但是您可以使用它来显示文件路径,如下所示。
当您在Finder窗口中时,单击顶部的 Go 并选择Go to Folder(Go to Folder)。
当对话框打开时,将文件拖放到输入字段中,它将填充您的文件路径。Command + C将路径复制到剪贴板。
使用终端查看文件路径
许多用户可能认为Mac上的(Mac)终端(Terminal)应用程序仅适用于程序员或喜欢编码的人。尽管这是真的,并且该应用程序确实允许您执行各种命令(app does allow you to execute various commands),但它也可以用于复制文件路径等基本任务。
该应用程序确实有助于显示文件路径,而且很容易做到。在Mac(Fire)上启动应用程序并将(Mac)文件拖放到其窗口中。所选文件的完整路径将出现在您的终端(Terminal)窗口中。
当您编写命令并且需要键入文件的完整路径时,它也很有用。您可以拖放文件而不是打字,它会为您填写所需的输入。
创建(Create)Automator 服务(Automator Service)以复制文件路径(Copy File Paths)
如果您使用的 macOS 版本不提供从上下文菜单复制文件路径的选项,您可以使用Automator服务自行将该选项添加到菜单中。Automator服务是一组用户定义的任务,这些任务在调用服务时执行。
这听起来可能过于程序化,但在实践中这样做并不难。事实上,它需要您做的就是将一个动作从这里拖放到那里,然后您就可以使用Automator准备好您的服务。
- 启动Automator应用程序并选择服务(Service),然后选择选择(Choose)。它将让您在您的机器上创建自定义服务。
Service receives selected - files or folders
in - Finder
- 在左侧面板中搜索名为“复制到剪贴板(Copy to Clipboard)”的操作并将其拖放到主面板上。
- 您的服务已准备就绪,是时候保存它了。单击(Click)顶部的文件(File),然后选择保存(Save)。输入服务的名称——这就是你右键单击文件时将出现的名称——然后点击Save。
您现在已准备好使用Mac上的上下文菜单复制文件路径。找到您要为其复制路径的文件,右键单击该文件,然后选择服务(Services),然后选择您的服务名称。
完整的文件路径将以纯文本格式复制到剪贴板。
额外提示(Bonus Tip):为Automator 服务(Automator Service)分配键盘快捷键(Keyboard Shortcut)
如果您想让复制文件路径变得更加容易,您可以为您的自定义Automator服务分配一个键盘快捷键。(you can assign a keyboard shortcut)因此,当您按下此组合键时,所选文件的路径将自动复制到剪贴板。
为此,请前往System Preferences > Keyboard > Shortcuts > Services,在列表中找到您的服务并为其提供您选择的键盘快捷键。
5 Ways To Reveal The Path Of a File On MacOS
When you create or copy a file to your Maс, it is assigned a path which is the actυal location of the file on your Mac. Paths let you easily get to any folder оr files on your machine as they represent the full address of the file saved on your machine.
Sometimes you may want to reveal the path of a file on your Mac for various reasons. Maybe you are writing a program that takes the file path as an input. Or maybe you have installed an app on your Mac and it asks you to enter the path of your file.
Regardless of why you want to reveal the path of a file, there are several ways to do so on your machine. macOS comes built with a number of options to help you view and even copy the full path of any file saved on your machine.
If that’s not easy enough for you, you can even create your own Automator service that copies the path of your selected file in a single click.
Also, feel free to check out our YouTube channel from our sister site where we go over the different methods in a short video.
Reveal File Paths Using The Info Box
If you have been using a Mac for some time, you may have likely seen the Get Info option that appears when you right-click on a file.
This option opens a box where all the information regarding your file is shown. This information includes the file name, file type, file size, and the most important one – file path.
To see it for yourself, open a Finder window, right-click on any of your files, and select Get Info.
On the following screen, look for the label that says Where and you will see the full path of your selected file on your Mac. It shows what folders and nested folders your file is located in.
While
it works great to help you find your file’s path, it does not let
you copy the file path as plain text if that is what you wanted to
do. You may want to check out some of the other methods mentioned
below if you want to copy the path of a file to your clipboard.
Copy File Paths From The Context Menu
The context menu on your Mac is a really powerful tool as it lets you do much more with your files than just letting you rename or delete your files.
One of the useful and hidden options in your context menu lets you directly copy the path of a file to your clipboard.
Since it’s hidden by default, it won’t appear when you right-click on a file on your Mac. However, unhiding the option is pretty easy and all it takes is pressing and holding down the Option key. This will make the option visible in your context menu.
To
use the option, right-click on a file in the Finder, hold down the
Option key on your keyboard, and you’ll see the Copy
“file-name.ext” as Pathname option. Click on it to copy your
file’s path.
It
will have copied the path of your selected file as plain text to your
clipboard.
Use Finder To View File Paths
You might think if Finder is a file management app, then why doesn’t it offer the feature to copy file paths? Unfortunately, the current version of the Finder doesn’t have an already visible option to copy file paths.
However, that doesn’t mean there really is no way to view your file paths using the Finder. There is indeed a feature – not built for revealing file paths – but helps you view your file paths on your machine.
It’s called the Go to Folder feature and it is actually built to help you go to a location on your Mac. But you can use it to reveal file paths as shown below.
While you are in a Finder window, click on Go at the top and select Go to Folder.
When the dialog box opens, drag and drop a file onto the input field and it will be filled with your file’s path. You may then copy the path to your clipboard using Command + C.
View File Paths Using
Terminal
Many users may think that the Terminal app on your Mac is only for programmers or for people who love coding. Although that’s true and the app does allow you to execute various commands, it can be used for basic tasks like copying file paths as well.
The app does help reveal file paths and it is pretty easy to do it. Fire up the app on your Mac and drag and drop a file onto its window. The full path of the selected file will appear in your Terminal window.
It’s also useful when you are writing a command and you need to type the full path of a file. Instead of typing, you can drag and drop the file and it will fill in the required input for you.
Create An Automator Service To Copy File Paths
If
you use a version of macOS that doesn’t offer the option to copy
file paths from the context menu, you can add the option to the menu
yourself using an Automator service. An Automator service is a
user-defined set of tasks that are performed when the service is
invoked.
That may sound too programmatic but doing so in practice isn’t that difficult. In fact, all it requires you to do is drag and drop an action from here to there and you have your service ready with Automator.
- Launch the Automator app and select Service followed by Choose. It will let you create a custom service on your machine.
- Configure the options at the top of the main panel as the following:
Service receives selected - files or folders
in - Finder
- Search for the action named Copy to Clipboard in the left panel and drag and drop it onto the main panel.
- Your service is ready and it’s time to save it. Click on File at the top and select Save. Enter a name for the service – this is what’s going to appear when you right-click on a file – and hit Save.
You’re now ready to copy file paths using the context menu on your Mac. Find the file you want to copy the path for, right-click on the file, and select Services followed by your service name.
The full file path will be copied to your clipboard in plain text formatting.
Bonus Tip: Assign a Keyboard Shortcut To The Automator Service
If you would like to make it even easier to copy file paths, you can assign a keyboard shortcut to your custom Automator service. So when you press this key combo, the path of the selected file will be automatically copied to your clipboard.
To do it, head to System Preferences > Keyboard > Shortcuts > Services, find your service in the list and give it your chosen keyboard shortcut.