• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 78
  • Last Modified:

Full Path Name to File on OSX El Capitan


I need to programmatically access a .TXT file via Javascript on my MacBook Air (OSX 10.11.6). I am a PC user and am not familiar with the file structure on a mac.

1. If I place the .TXT file on my desktop, what will the path be?
2. If I place the .TXT file in my Documents folder, what will the path be?

FYI, here is the simple Javascript that I'm playing with just now (I would prefer the path to be absolute and not a relative path as I'm not sure where the Javascript will be triggered from yet).

myPath = "~/Desktop/source.txt";

Thanks very much for your help!
3 Solutions
The simplest way to find a path name on a Mac is to open a terminal window and drag and drop the file into the window. This will add the full path name to the window and you can copy and paste it.
bbaoIT ConsultantCommented:
the full pathname is '/users/your name/desktop/source.txt' where 'yourname' is your actual username. or simply use 'users/yourname' to replace all '~' in your code.
Eoin OSullivanConsultantCommented:
OK .. if this script is ONLY on your MacBook and ONLY when your specific user is logged in then you can use the ABSOLUTE paths which are as follows .. (replace USERNAME with the user you login with)

Open in new window


Open in new window

However if there is a chance that the script will be used on other computer or by other users the relative path is perfectly good.  The tilde (~) character which == Home folder for the currently logged in user is a completely standard Unix format and almost ALL applications and scripts can quite happily work with it and you can use the "~/" instead of "/Users/USERNAME/" almost everywhere
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now