在登录时启动的shell脚本中的Mac OS(OS X) [英] Launch shell script on login in Mac OS (OS X)

查看:444
本文介绍了在登录时启动的shell脚本中的Mac OS(OS X)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的shell脚本 Test.sh

I have this shell script Test.sh:

#! /bin/bash

FILE_TO_CHECK="/Users/test/start.txt"
EXIT=0

while [ $EXIT -eq 0 ]; do
    if [ -f "$FILE_TO_CHECK" ]
        then
        /usr/bin/java -jar myapp.jar
        EXIT=1
    else
        sleep 30
    fi
done

我需要登录后自动启动此脚本。结果
所以,我把它放在一个文件夹测试里面 /系统/库/ StartupItems /

当我重新启动Mac,没有我在登录后发生的。
任何线索?

When I reboot the Mac, nothing happens after I log in. Any clue?

我也试过的Automator ,但具有相同的结果:Java程序没有运行

I also tried Automator, but with the same result: the java program is not running.

推荐答案

您不能只是将普通的脚本文件夹中。你需要的专业包的苹果是如何调用它,基本上是与你的可执行文件夹,和的.plist 配置。你应该把它放在 /库/ StartupItems ,因为 /系统/库/ StartupItems / 已预留给操作系统。阅读所有关于它在这里:

You can't just place plain scripts in that folder. You need a "specialized bundle" how Apple calls it, basically a folder with your executable, and a .plist configuration. And you should put it in /Library/StartupItems since /System/Library/StartupItems/ is reserved for the operating system. Read all about it here:

<一个href=\"https://developer.apple.com/library/mac/documentation/macosx/conceptual/bpsystemstartup/chapters/StartupItems.html\" rel=\"nofollow\">https://developer.apple.com/library/mac/documentation/macosx/conceptual/bpsystemstartup/chapters/StartupItems.html

另外请注意,整个东西被标记为的德precated技术的。和苹果暗示使用的launchd的。有一个例子,如何设置它在这里:

Also note that the whole stuff is marked as deprecated technology. And that Apple is suggesting the use of launchd. There is an example how to set it up here:

<一个href=\"http://superuser.com/questions/229773/run-command-on-startup-login-mac-os-x\">http://superuser.com/questions/229773/run-command-on-startup-login-mac-os-x

这篇关于在登录时启动的shell脚本中的Mac OS(OS X)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆