Skip to main content
Question

Creating Alias on User Desktop at Login


Forum|alt.badge.img+8

Hello! I am trying to create an alias for 3 folders that live in /Users/Shared on every User's Desktop when they log in.

I am using this...

#!/bin/sh

#Gets Current Logged In User and Creates Alias 
ln -s /Users/Shared/Folder 1 /Users/$(who | awk '/console/{ print $1 }')/Desktop/Folder 1 
ln -s /Users/Shared/Folder 2 /Users/$(who | awk '/console/{ print $1 }')/Desktop/Folder 2 
ln -s /Users/Shared/Folder 3 /Users/$(who | awk '/console/{ print $1 }')/Desktop/Folder 3

I have the policy trigger to run at login and once per user.

I am getting a failed message...

Script result: ln: /Users//Desktop/Folder 1: No such file or directory ln: /Users//Desktop/Folder 2: No such file or directory ln: /Users//Desktop/Folder 3: No such file or directory

It looks like it is not finding the User. Can I some direction on where my script is wrong? When I run this manually on a computer it is successful.

Thanks bunch!

Lisa Rosbrook

4 replies

Forum|alt.badge.img+14
  • Contributor
  • 74 replies
  • April 8, 2016

I tried running it just from a jamf -event call and it looks like it works fine. Judging from how you're getting the user using the "who" command, I'm guessing that it's calling the script before the console session gets fully established, because it's returning a value of null when you're trying to set that as the current console user's folder path.

Maybe try throwing in a "sleep 5" before you try running the symlink commands and see if that does the trick?


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • April 8, 2016

@NoahRJ is likely correct. The telltale sign is the line in the error stating:

No such file or directory ln: /Users//Desktop/Folder 2

Notice the missing account name between /Users/ and /Desktop/ Its not getting the username.

Also, I would avoid using who | awk '/console{print $1}' to get the user. its not the most reliable way to do it.
Try swapping it out with:

$(stat -f%Su /dev/console)

davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • 1811 replies
  • April 9, 2016

If you are running it at login you can use the standard Casper variable $3 so /Users/$3/Desktop/Folder 1


Forum|alt.badge.img+12
  • Contributor
  • 529 replies
  • April 11, 2016

+1 for all of the above. Unless you create a LaunchAgent, you can't be sure that /dev/console is running before your script runs.

As @davidacland suggested, $3 will work at login, Casper is doing that work for you, but I'd avoid a sleep command as this could vary on success.

You could also add to User Template.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings