Creating an Alias

eculp
New Contributor

I'm new to writing scripts in OS X. I need to copy a file (or preferably an alias) to the user's desktop. It is our AUP (in PDF form) that the board has decided needs to be on the desktop. I want to set it up as a script so if the user deletes it, I can push it back out via every15.
Any help would be great fully appreciated.

Eric

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

So, there are several ways you can approach this one. Here are just two. I'm sure others will chime in with additional methods.

1- Copy the PDF file in question to your Desktop, open Composer and drag/drop it into an empty spot on the left. It will create a new Source and pull in the doc with a path like /Users/yourHomeFolder/Desktop/FileName.pdf.
Create a DMG (not PKG), upload to your JSS, then be sure to check the Fill Existing Users checkbox (optionally the Fill User Template one too) once its in Casper Admin.
Deploy it via a policy as a Once per User trigger (again making sure to check the FEU and/or FUT boxes) and the JSS will drop the PDf file to everyone's Desktop when they log in.

2- Drop the PDF file into a common location on your admin Mac, like /Users/Shared/
Follow the same steps as above to capture your PDF in Composer. You can build it as either a PKG or DMG this time.
Add to your JSS, add in a policy to get it deployed to your Macs, and then use the Run Command option in the Advanced tab of the policy to do something like this:

ln -s /Users/Shared/FileName.pdf /Users/$(who | awk '/console/{ print $1 }')/Desktop/FileName

The above creates an alias of the file in /Users/Shared to the current logged in users Desktop.

As far as making sure it gets added again if someone deletes it, there are some ways you can accomplish this with an Extension Attribute, Smart Groups and ongoing policies but, I believe this may be a good use of something almost never used by anyone in Casper, which is the Self Healing function. Self Healing doesn't really work for applications, but it can sometimes work well for ensuring a document or link is always present. Read up on it in the full Casper Admin guide. The documentation is a little weak on how it works, but it should at least point you in the right direction.

View solution in original post

4 REPLIES 4

mm2270
Legendary Contributor III

So, there are several ways you can approach this one. Here are just two. I'm sure others will chime in with additional methods.

1- Copy the PDF file in question to your Desktop, open Composer and drag/drop it into an empty spot on the left. It will create a new Source and pull in the doc with a path like /Users/yourHomeFolder/Desktop/FileName.pdf.
Create a DMG (not PKG), upload to your JSS, then be sure to check the Fill Existing Users checkbox (optionally the Fill User Template one too) once its in Casper Admin.
Deploy it via a policy as a Once per User trigger (again making sure to check the FEU and/or FUT boxes) and the JSS will drop the PDf file to everyone's Desktop when they log in.

2- Drop the PDF file into a common location on your admin Mac, like /Users/Shared/
Follow the same steps as above to capture your PDF in Composer. You can build it as either a PKG or DMG this time.
Add to your JSS, add in a policy to get it deployed to your Macs, and then use the Run Command option in the Advanced tab of the policy to do something like this:

ln -s /Users/Shared/FileName.pdf /Users/$(who | awk '/console/{ print $1 }')/Desktop/FileName

The above creates an alias of the file in /Users/Shared to the current logged in users Desktop.

As far as making sure it gets added again if someone deletes it, there are some ways you can accomplish this with an Extension Attribute, Smart Groups and ongoing policies but, I believe this may be a good use of something almost never used by anyone in Casper, which is the Self Healing function. Self Healing doesn't really work for applications, but it can sometimes work well for ensuring a document or link is always present. Read up on it in the full Casper Admin guide. The documentation is a little weak on how it works, but it should at least point you in the right direction.

talkingmoose
Moderator
Moderator

Here's a launchd way of doing this. You can change the pvt.talkingmoose domain and TalkingMoose folder to names of your choosing.

You'll need to use Composer to create a new package.

  1. Add your PDF to your Composer window under a path that Standard users can't modify such as /Library/TalkingMoose/.
  2. Copy the following text into a file called pvt.talkingmoose.StickyFile.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <false/>
    <key>Label</key>
    <string>pvt.talkingmoose.StickyFile</string>
    <key>ProgramArguments</key>
    <array>
        <string>osascript</string>
        <string>-e</string>
        <string>tell application "Finder" to duplicate POSIX file "/Library/TalkingMoose/AUP.pdf" to Desktop with replacing</string>
    </array>
    <key>QueueDirectories</key>
    <array/>
    <key>RunAtLoad</key>
    <true/>
    <key>StartInterval</key>
    <integer>900</integer>
    <key>WatchPaths</key>
    <array/>
</dict>
</plist>
  1. Edit the path in line 13 to point to your AUP.pdf file.
  2. Edit line 20 if you want to change from running this every 15 minutes (900 seconds) to something different.
  3. Add the pvt.talkingmoose.StickyFile.plist file to your Composer window under /Library/LaunchAgents/.
  4. Save the package as either a .dmg or .pkg file and deploy.

Fortunately, launchd includes a WatchPaths parameter to trigger something to happen if a file or folder changes. Unfortunately, you can't use tildes or wildcards and tell it to watch or affect the current user's Desktop.

This will copy the file to the current user's Desktop instead of creating an alias. The AppleScript command to copy the file will allow replacing an existing file rather than multiplying it. The AppleScript command to create an alias will only multiply the files without additional scripting.

eculp
New Contributor

@mm2270: I went with option #2 and it works great. I really prefer to just create an alias instead of pushing the whole file down, since many times they will be off site.

@talkingmoose: Thanks for the response. I'm going to look at that script once I have time. Looks like something I can use on another project.

Thanks for the quick responses. Ya just gotta love this board!

Eric

apizz
Valued Contributor

Know this thread is a bit old, but we've been putting our AUP in an .rtf file located in /Library/Security/PolicyBanner.rtf. As long as the file is named PolicyBanner.rtf, the AUP will appear in the form of a message at the login screen which the user must accept in order to login to use the computer.

Then you don't have to worry about aliases at all, you can just put the PolicyBanner.rtf file in the folder you want it to be and then drag it to composer to make a package to push out to all your computers.