You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

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

Creating a link from Numbers to a PDF doc

How do I create a link from my Numbers spreadsheet to a pdf document. I am using Numbers to keep track of my Tenants payments. It would be nice if I can click on a link taking me directly to my Tenants lease agreement which is stored in pdf format on my Mac

Posted on Dec 24, 2021 5:31 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 24, 2021 1:01 PM

There is, using AppleScript and Automator. Right now scripting for iWork has a major bug but luckily there is a workaround. The workaround version of the script is posted below.


  1. Open Automator and create a new "quick action". Set it to take "no input" in application Numbers
  2. From the utilities folder, drag the "run AppleScript" action to the window
  3. Delete the default contents in the action
  4. Copy/paste the script from below into the action
  5. Save the "quick action" with a descriptive name


Test it out

  1. In a cell in a Numbers table, put a path to a file like described at the top of the script. I believe correct capitalization matters in the path name and file name. In Finder at the bottom of a Finder window you can get the pathname and filename with the correct capitalization. At the bottom of the window is the pathbar (you may have to turn it on in the View menu). With a file selected, right click on the filename in the pathbar and "copy as pathname".
  2. Select that cell (single click)
  3. In the Numbers menu is a menu item named Services. In that you should see your new "quick action" (service). Click on it.
  4. Hopefully your file opened.


Assign a keyboard shortcut to the service.

  1. System Preferences/Keyboard/Shortcuts/App Shortcuts
  2. If Numbers is already on the list, select it. If not continue to next step
  3. Hit the + to make a new shortcut
  4. Application should be Numbers
  5. Menu Title needs to be exactly the same as the name of your new service. Same punctuation, capitalization, everything.
  6. Choose the key combo you want to use
  7. Hit OK
  8. Now back in Numbers you can use the key combination to open your linked file.


Hopefully that all works. With all the new permissions on file/folder access you might get asked to allow it to access whatever folder your files are in.


-- Opens a file where the path is specified in a Numbers cell.
-- The path should be a POSIX path such as "/Users/username/Desktop/filename.png"
-- A range of cells may be selected to open multiple files at once.
-- The path can be to a folder, and the folder will open
-- It is envisioned that this script would be turned into a Service for Numbers
-- and invoked with a keyboard shortcut after selecting the cells.

tell application "Numbers" to tell front document
	tell active sheet
		tell (first table whose class of selection range is range)
			set therange to every cell of range (get name of selection range)
			
			if (number of cells in therange) > 5 then display dialog "Open more than five documents?"
			
			repeat with c in the therange
				set filepath to (value of c)
				try
					do shell script "open " & quoted form of filepath
				end try
			end repeat
		end tell
	end tell
end tell

12 replies
Question marked as Top-ranking reply

Dec 24, 2021 1:01 PM in response to hwpienaar

There is, using AppleScript and Automator. Right now scripting for iWork has a major bug but luckily there is a workaround. The workaround version of the script is posted below.


  1. Open Automator and create a new "quick action". Set it to take "no input" in application Numbers
  2. From the utilities folder, drag the "run AppleScript" action to the window
  3. Delete the default contents in the action
  4. Copy/paste the script from below into the action
  5. Save the "quick action" with a descriptive name


Test it out

  1. In a cell in a Numbers table, put a path to a file like described at the top of the script. I believe correct capitalization matters in the path name and file name. In Finder at the bottom of a Finder window you can get the pathname and filename with the correct capitalization. At the bottom of the window is the pathbar (you may have to turn it on in the View menu). With a file selected, right click on the filename in the pathbar and "copy as pathname".
  2. Select that cell (single click)
  3. In the Numbers menu is a menu item named Services. In that you should see your new "quick action" (service). Click on it.
  4. Hopefully your file opened.


Assign a keyboard shortcut to the service.

  1. System Preferences/Keyboard/Shortcuts/App Shortcuts
  2. If Numbers is already on the list, select it. If not continue to next step
  3. Hit the + to make a new shortcut
  4. Application should be Numbers
  5. Menu Title needs to be exactly the same as the name of your new service. Same punctuation, capitalization, everything.
  6. Choose the key combo you want to use
  7. Hit OK
  8. Now back in Numbers you can use the key combination to open your linked file.


Hopefully that all works. With all the new permissions on file/folder access you might get asked to allow it to access whatever folder your files are in.


-- Opens a file where the path is specified in a Numbers cell.
-- The path should be a POSIX path such as "/Users/username/Desktop/filename.png"
-- A range of cells may be selected to open multiple files at once.
-- The path can be to a folder, and the folder will open
-- It is envisioned that this script would be turned into a Service for Numbers
-- and invoked with a keyboard shortcut after selecting the cells.

tell application "Numbers" to tell front document
	tell active sheet
		tell (first table whose class of selection range is range)
			set therange to every cell of range (get name of selection range)
			
			if (number of cells in therange) > 5 then display dialog "Open more than five documents?"
			
			repeat with c in the therange
				set filepath to (value of c)
				try
					do shell script "open " & quoted form of filepath
				end try
			end repeat
		end tell
	end tell
end tell

Dec 26, 2021 3:44 AM in response to hwpienaar

Pretty link names are easily done with the store-in-Dropbox method. Just triple-click in the white space of cell, not the link itself, so all text within the cell is selected, then option-click > Edit Link and change Display: to whatever you want.



That's one of the advantages of this method. I find the difference in speed insignificant in normal usage, as I'm not constantly opening different documents to view them from Numbers. The difference might become significant if I had to do this every few seconds or so, but in normal usage I don't notice much of a lag.


SG

Dec 24, 2021 7:06 AM in response to hwpienaar

Unfortunately that is not a built-in feature of Numbers.


You can link to a file online, such as one stored in iCloud or Dropbox. That is the usual method.


You can use the Apache server that comes with Mac OS to turn your Mac into a server, which can serve up your local files to Numbers. While not hard to do it hardly seems worth it and it may bring up some security vulnerabilities.

Dec 24, 2021 6:14 PM in response to hwpienaar

I've found that by far the simplest and most practical solution is to store the pdf (or whatever) file in Dropbox or another service that allows copying of an item link. Just copy the item link (find the file in the Dropbox folder on your Mac, then control-click and choose from the contextual menu) and paste the link into a Numbers cell. You can then just click the link to call up the file. Dropbox has a free tier so you can see how it works. And if you don't have a lot of bulky documents that you want to access from Numbers then you may not need a paid tier.


SG

Dec 26, 2021 7:54 AM in response to hwpienaar

The script needs the full path. It has to get it some way but not necessarily all of it from a cell.


I believe it could be modified to automatically determine the saved location of the Numbers file and use that path as the path for the PDF files. All PDF files would have to be saved in the same folder as the spreadsheet but your cells would require only the filenames. It could also tack a folder name, like "Data Folder" onto the path so all the data files could be in a subfolder. The script is less universal that way but nicer for when the spreadsheet and all its files should be kept together. I know how to get the full path of the active Numbers document but I'm not sure how to hack the filename from the end of it in order to replace it with a subfolder name (if desired) and a filename from a cell.


It could be modified to automatically tack a specific "/Users/username/" and even a folder name to whatever it gets from the cells in your table. You would then only have to specify a folder and filename or just a filename. This would make the script a lot less useful in general, though.


You could use the script as is and change the cell format of the cells that have the filepaths to display the word "File" or some other static text in the cell vs displaying the actual filepath.

Creating a link from Numbers to a PDF doc

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