Deploying a web link to Macbook Desktop


Hello, I've found this script and it is working fine (to create the file). But when trying to open the actual file [link] from the desktop, it gives an error.

Screenshot 2024-03-19 at 4.41.26 PM.png

I noticed that the permissions show this file as being owned by ROOT, since it is populated through a script via Jamf, but I'm not sure if that's the issue. If I try to create my own webloc file by dragging a webpage from Safari to my Desktop, that works just fine. But not one created by this script.


Contributor III

You may have more luck making the file an internet shortcut... Essentially this is a file of type "FileName.url" with content:


We create these in /Library and link them to the users dock, but putting it on the desktop should still work... The other option I can think of is to generate the file as the user using a function like:

ACTIVE_USER=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )

# Function to run command as user
run_as_user() {  
	if [[ "${ACTIVE_USER}" != "loginwindow" ]]; then
    	User_ID=$(id -u "$ACTIVE_USER")
		launchctl asuser "$User_ID" sudo -u "${ACTIVE_USER}" "$@"
		echo "no user logged in"
		exit 0;

Esteemed Contributor II

@janzaldua Here's the post I made a while back with a script to create a .webloc that properly sets permissions:

Thank you! I believe this is working. It seems to be a permissions issue. Appreciate you!

Edit: I may have spoken too soon. When I tried to replace the string with my own link that I need to deploy, I get the same error. "The document could not be opened."

To give some context, the link/url is an Internal Service Now link.

Esteemed Contributor II

@janzaldua What happens if you try replacing the string with some other web site instead of your Service Now link? I'm curious if that allows you to create a working .webloc.

When using your original script, it worked fine actually. But once I changed the URL to my own (Service Now link), it wouldn't open and I would get the error. So I assume it doesn't like my service now URL, for some reason...