Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'running generatelinks.sh' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
running generatelinks.sh
Authored by: Skurfer on Nov 04, '05 07:40:20AM

Rob mentions using "cron or some other mechanism to run the generatelinks.sh script".

If I understand the way it works, launchd would be a great "other mechanism" because it can be configured to run generatelinks.sh whenever the /Applications directory is changed.

You could create a new plist for launchd in ~/Library/LaunchAgents (since it only needs to be active when you're logged in) and include something like this in the file:

<key>WatchPaths</key>
<array>
  <string>/Applications/</string>
</array>

The only thing I wonder about is whether or not launchd considers you to be "logged in" if you come in remotely via SSH, but I suppose in that case, you're not likely to modify the Applications folder or launch the applications themselves.



[ Reply to This | # ]
running generatelinks.sh
Authored by: GlowingApple on Nov 04, '05 09:20:44AM
So I would need to create the folder LaunchAgents if it doesn't exist and then put a .plist file in that directory with

<key>WatchPaths</key>
<array>
  <string>/Applications/</string>
</array>
as the only text? Do I need to have a special name for this file and is there anything I need to do to have launchd start checking it? (i.e. restart the service or log out/ log in) Thanks!

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."

[ Reply to This | # ]

running generatelinks.sh
Authored by: nick on Nov 04, '05 10:33:02AM
the file gotta look s/th like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-
1.0.dtd">
<plist version="1.0">
<dict>
        <key>Debug</key>
        <true/>
        <key>Label</key>
        <string>generatelinks</string>
        <key>LowPriorityIO</key>
        <true/>
        <key>Nice</key>
        <integer>10</integer>
        <key>Program</key>
        <string>/Users/nick/Apps/generatelinks.sh</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Users/nick/Apps/generatelinks.sh</string>
        </array>
        <key>ServiceDescription</key>
        <string>generate links for commandline GUI-app launching</string>
        <key>UserName</key>
        <string>nick</string>
        <key>WatchPaths</key>
        <array>
                <string>/Applications/</string>
        </array>
</dict>
</plist>
of course you should adapt the path to the script AND the username. you can make this plist with launchd editor (its on vt, me thinkin) or with the plist-editor (its on your system). the you tell osx to add it to launchd-services:

:~ nick$ launchctl load Library/LaunchAgents/generatelinks.plist 
:~ nick$ launchctl list 
again adapt paths. if you now add s/th to /Applications/ you'll notice the find-process in top. but this way, if you remove apps, they aren't removed from your list. you gotta add s/th like "rm ~/Apps/*.app" to generatelinks.sh for this. then everytime you s/th to /Applications/ the complete list of links is rebuild. this could be a problem with apps writing in their app-bundle though, as the find-command takes its time... regards, n.

[ Reply to This | # ]
running generatelinks.sh
Authored by: GlowingApple on Nov 04, '05 04:28:29PM
Thanks! Works great. I changed the code of the original script a bit to be more conducive to a background task:

#!/bin/sh

cd ~/Apps
find -E /Applications/ -regex ".*.app$" -print |
while read APPS; do
  APPLINK=`echo -n "$APPS" | sed s:".*/":"": | sed s:" ":"_":g`
  if [ ! -e "$APPLINK" ]; then
         ln -s open.sh "$APPLINK"
         logger "Created Application symlink for "$APPLINK
  fi
done
This will verify if the symlink exists first, otherwise when it tries to overwrite it generates an error. It will also output the names of the links it creates to the system log, rather than to stdout, which running within launchd isn't really visible. This doesn't cover the problem with apps removed, but simply doing an rm ~/Apps/*.app periodically should fix this.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."

[ Reply to This | # ]

running generatelinks.sh
Authored by: GlowingApple on Nov 04, '05 09:20:44AM
So I would need to create the folder LaunchAgents if it doesn't exist and then put a .plist file in that directory with

<key>WatchPaths</key>
<array>
  <string>/Applications/</string>
</array>
as the only text? Do I need to have a special name for this file and is there anything I need to do to have launchd start checking it? (i.e. restart the service or log out/ log in) Thanks!

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."

[ Reply to This | # ]

running generatelinks.sh
Authored by: GlowingApple on Nov 04, '05 09:22:55AM

Oops, accidental double-click...sorry for the dup. post.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]