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.

Hyperlink in Numbers.

In number cell how can I add hyperlink for a pdf document stored in local files as well as desktop ?

Actually I want to make a number file which will redirect to individual PDF files stored in my Mac local folder.


Thanks in advance.

MacBook Pro 15″, macOS 11.3

Posted on May 2, 2021 11:45 PM

Reply
Question marked as Top-ranking reply

Posted on May 3, 2021 9:55 AM

You can do something like this:


tell front document of application "Numbers"
	tell active sheet
		tell (first table whose class of selection range is range)
			set v to value of first cell of selection range
		end tell
	end tell
end tell
do shell script "open " & quoted form of v


Where the value in the cell is something like this on my machine:


/Users/sg3/Desktop/green-right-v.png


But I find it more convenient to click a Dropbox file link.


SG




SG

9 replies
Question marked as Top-ranking reply

May 3, 2021 9:55 AM in response to Badunit

You can do something like this:


tell front document of application "Numbers"
	tell active sheet
		tell (first table whose class of selection range is range)
			set v to value of first cell of selection range
		end tell
	end tell
end tell
do shell script "open " & quoted form of v


Where the value in the cell is something like this on my machine:


/Users/sg3/Desktop/green-right-v.png


But I find it more convenient to click a Dropbox file link.


SG




SG

May 3, 2021 6:31 AM in response to Yellowbox

After all these years do we not have a script that will take a selected cell or range of cells containing file paths and open the file(s)? I'd put one together but for the life of me I can't figure out how to open a file based on the POSIX path provided in a cell. I can open one if I put the path in quotes directly in my script but not if I get it from a cell. I was able to open a file that used colons instead of slashes in the path in the cell but that style is not normal for most people.


It would not be "click to open" but it could be set to a simple key combination

May 3, 2021 2:51 PM in response to SGIII

Thanks for that. I could have sworn I tried that shell script line but I must have had something different. I deleted what I was working on this morning so no way to tell what I was doing wrong.


One advantage of a script, aside from not having to upload documents to Dropbox, is you can open multiple documents at the same time. Here are two versions of what I had in mind. The first uses the Applescript path such as "Macintosh HD:Users:badunit:Desktop:grant.png" The second uses the POSIX path like your script "/Users/badunit/Desktop/grant.png". Both allow a range of cells to be selected and their files opened in one call to the script. Invalid paths are skipped. I do wonder how many it can handle before it misbehaves. I've only tried it on three at a time. A limit could be implemented if necessary.


Anyway, if a script invoked by a keyboard shortcut would be a usable solution, the OP has a few to choose from.


tell application "Numbers" to tell front document
	tell active sheet
		tell (first table whose class of selection range is range)
			if (number of cells in selection range) > 5 then display dialog "Open more than five documents?"
			
			repeat with c in (get selection range)'s cells
				set filepath to (value of c)
				try
					tell application "Finder" to open file filepath
				end try
			end repeat
		end tell
	end tell
end tell


tell application "Numbers" to tell front document
	tell active sheet
		tell (first table whose class of selection range is range)
			if (number of cells in selection range) > 5 then display dialog "Open more than five documents?"
			
			repeat with c in (get selection range)'s cells
				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


May 9, 2021 3:36 AM in response to Rabiul5040

Thanks everyone for your suggestions.

Anyway, I got a way around.

We can easily use the localhost web server to store and link file.

I have create a structured way so that anyone may follow and be helped.

 Hyperlinking cells to local document files in Numbers

Step:1 (Checking localhost is working or not)
-> go to a web browser and type the following , and then hit enter localhost
If the page says “It works” - localhost is working/ Local server is open
If the page do not find any page- localhost is not working/ Local server is blocked

Step:2 (Starting a localhost in Macbook Pro)

-> open up terminal

copy and paste the following command, and then hit enter:

cd ~

now, copy and paste the following command, and then hit enter:

sudo apachectl start

Step:3 (Checking that localhost is working)

-> go to a web browser and type the following command, and then hit enter localhost
If the page says “It works” - localhost is working/ Local server is open

Step:4 (Saving a document in localhost server)

-> open finder and go to the following directory

Rabiul’s Mac -> Library -> WebServer -> Documents

In the Documents folder you can do the any of the following two thing:
1. Create a new folder (say “XYZ”) and save your file (abc.pdf) in that folder 2. Save your file (abc.pdf) in the “Documents” holder

Step:5 (Linking the file in Numbers)

-> open up Numbers
select the content of a cell that you want to link
to hyperlink: go to the format panel -> add link -> Web page Now select “Link to: Web page”
in the link bar, write your address in the following manner:

1. Say you have followed “Create a new folder (say “XYZ”) and save your file (abc.pdf) in that folder”. Then,

localhost/XYZ/abc.pdf

Now, hit open link. Your file should be hyperlinked

2. Say you have followed “Save your file (abc.pdf) in the “Documents”
 folder. Then

localhost/abc.pdf

Now, hit open link. Your file should be hyperlinked
as you can see, whatever you do in the Documents folder under you web server you will have to link from there. Say, you have create a folder “ABC” in Documents folder. And again under ABC folder created another folder “DEF”. Now, you save a file (abc.pdf) in this DEF file. In this case your link for the Number will be:
localhost/ABC/DEF/abc.pdf

Step: 6 (If you want to close localhost, just copy-paste the command and hit enter)
-> sudo apachectl stop


Thanks again.

May 9, 2021 7:45 AM in response to Rabiul5040

That's cool. Everything up until the "stop" part worked as you said but if I type localhost into Safari it continues to say "it works" and I can get to the files via Safari after "sudo apachectl stop" and even after I reboot. The links I had in Numbers won't go there, though. How do you get it back to how it was at the beginning?


EDIT: Never mind. It was just pulling up the cached files. I cleared the Safari cache for localhost and all is back as it was.

May 9, 2021 7:47 AM in response to Badunit

Badunit wrote:

That's cool. Everything up until the "stop" part worked as you said but if I type localhost into Safari it continues to say "it works" and I can get to the files via Safari after "sudo apachectl stop" and even after I reboot.


Well, you could try a clean install of the OS.😀.


But maybe not necessary.


I went to Safari > Preferences > Privacy > Manage Website Data... and cleared out the localhost cache.


SG

May 9, 2021 1:26 PM in response to SGIII

Well, you could try a clean install of the OS.😀.

That always remains an option to fix whatever oddities cannot be solved otherwise. There was a time when I would do this periodically, and reinstall all apps from scratch (along with all their updates and patches), just to clear out all the detritus, especially when I was on a PC running Windows. Now there are so many settings to redo, so many apps to reinstall, and so many saved password, shortcuts, etc. that would be lost in such an operation.

Hyperlink in Numbers.

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