开发者

osx launchd plist with dynamic login username

Is possible to dynamic username(regard with logged in user) in .plist file for launchd.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-/开发者_Go百科/Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>com.software.script</string>
    <key>Program</key>
    <string>/Users/$username/script.sh</string>
    <key>RunAtLoad</key>
    <true/>
</dict>

I want username is vary with logged in user like this.

<string>/Users/user1/script.sh</string>

or

<string>/Users/user2/script.sh</string>

or

<string>/Users/usern/script.sh</string>

Thank you.


Since nobody answered this... My solution would be to have a single script in a single location such as /usr/local/bin that just calls the appropriate user's script. Something like this:

#!/bin/bash
/Users/`id -un`/script.sh

Or I am not sure if $HOME would be set but you might be able to use that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜