简体   繁体   English

启动具有相对路径的代理

[英]Launch Agent with Relative Path

Is it possible to execute a script in the current user's home directory with a ~/Library/LaunchAgents/ agent? 是否可以使用~/Library/LaunchAgents/ agent在当前用户的主目录中执行脚本? I current have (not working): 我目前有(不工作):

<?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>Label</key>
        <string>com.puppies</string>
        <key>OnDemand</key>
        <true/>
        <key>RunAtLoad</key>
        <true/>
        <key>ProgramArguments</key>
        <array>
          <string>/bin/sh</string>
          <string>~/script.sh</string>
        </array>
        <key>StartInterval</key>
        <integer>3600</integer></dict>
</plist>

Set EnableGlobbing to true: 将EnableGlobbing设置为true:

<key>EnableGlobbing</key>
<true/>
<key>ProgramArguments</key>
<array>
    <string>say</string>
    <string>~/*</string>
</array>

EnableGlobbing enables expanding tildes and globs in ProgramArguments but not in Program. EnableGlobbing可以在ProgramArguments中扩展波浪号和全局,但不能在Program中扩展。 Tildes are expanded in WatchPaths and QueueDirectories by default. 默认情况下,Tildes在WatchPaths和QueueDirectories中进行了扩展。

Do as below 请执行以下操作

<key>ProgramArguments</key>
    <array>
      <string>zsh</string>
      <string>-c</string>
      <string>/bin/sh</string>
      <string>~/script.sh</string>
    </array>

I frequently use the following in OS X: 我经常在OS X中使用以下内容:

<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>-c</string>
<string>lb=/Users/`users`/Library; 

So you could try replacing your tilda with: 所以你可以尝试用以下方法替换你的tilda:

/Users/`users`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM