原标题:
Launch shell script silently at login
In OSX I needed a shell script to execute at login. There are a few different ways to perform this so I thought it might be helpfulto document what your options are. I've switched over to Emacs which typically has a longer startup time than editors such as Vim. This is the shell script we will execute:
#!/bin/zshemacs --daemon
Oftentimes Emacs will stay open during an entire user session of the OS, so the sooner I can launch it the better. OSX offers a few different startup options for us. First, we have Login Items available within Account Settings of the System Preference pane. We need to rename the shell script above to end in a .command file extension to allow the Login Items to execute it. This will run at login, however we will be left with a Terminal prompt visible when the script has completed. Preferably we would execute this in the background at user login. OSX manages system and user daemons via a tool called launchd. The interface to launchd is a tool called launchctl which allows for loading and unloading daemons into launchd. XML formatted plist files are used to describe operations loaded into launchctl.
<plist version="1.0"> <dict> <key>Label</key> <string>emacs-daemon</string> <key>RunAtLoad</key> <true /> <key>Program</key> <string>/Users/nickp/bin/scripts/launch-emacs-daemon.sh</string> </dict> </plist>
The above file, emacs-daemon.plist needs to be saved in the ~/Library/LaunchAgents directory. As you can see the xml dictates that the launch-emacs-daemon.sh file should be executed at load, note we no longer need a .command file extension. We will now use launchctl to load our plist file.
launchctl load ~/Library/LaunchAgents/emacs-daemon.plist
To verify that your script executed correctly lets ask launchctl to show us what is running.
launchctl list | grep emacs
You will likely see two entries, each with three columns. Mine looks like this:
148-0x100100e80.anonymous.emacs-0emacs-daemon
The first column is the process id, the first row shows the PID of the emacs daemon our shell script spawned. The second line is the emacs-daemon.plist job entry that executed, returning a status code of zero in the second column - success! With this setup, I can launch the emacsclient process which will attach to the daemon server and launch instantly.
相关推荐
mac 下 apk自动签名 shell脚本
Shell脚本专家指南》旨在为Linux、Unix以及OSx系统管理员提供短小精悍且功能强大的shell实现解决方案,教会读者如何使用现有调试器调试shell脚本。全书分为3个部分:脚本技术基础、系统交互和高级技术、有用的脚本...
shell 脚本。 特征 配置默认的 OSX 设置。 使用以下公式安装: 下载和安装软件包一般不在: 下载并安装软件扩展: 要求 (并且接受许可协议) 设置 打开终端窗口并根据您的版本首选项执行以下设置序列之一: 当前...
捆绑在 shell 脚本中的优化和调整。 #关于 由于提高操作系统性能、安全性、行为等,此脚本修改了多个 OSX 配置设置。 #警告 尽管此更改通常会改善系统统计信息,但您应该在使用它之前考虑您的系统管理员/开发...
脚本不会根据目的验证和修复可能的链接警告。 因此,您有时可能会看到类似以下消息:“警告:您的地窖中有未链接的小桶。” brew_check.sh 显示已安装的Pip软件包的软件包信息。 更新pip3软件包并以直接方式pip...
brewski:Bash shell脚本,可使用Homebrew自动安装MacOS应用程序和软件包
##Mac OS X 主题适用于 Ubuntu 14.04 和 14.10 这是一个 shell 脚本,用于安装 Mac OS X Yosemite GTK 主题以及图标、徽标和其他小技巧,为您的 Ubuntu 机器提供完整的 Mac OSX 体验。 此脚本适用于 Ubuntu 14.04 和...
android-shell-scripts:帮助与Android设备配合使用的Shell脚本
另一个番茄钟定时器 shell 脚本停止寻找番茄钟定时器应用程序,如果你有一个类 Unix 的 shell,你可以在一个 shell 行中破解一个: sleep $[60 * 25] ; echo " Pomodoro Finished! " 这个脚本基于这个简单的想法,但...
iterm-fish-fisher-osx:完整的指南和Bash脚本,用于安装命令行工具+自制软件+ iTerm2 + Fish Shell + Fisher +插件用于开发目的
libVLC在OSX10.11系统+XCode7.3的环境下正确编译的全过程,将shell脚本打印出来,大家可以参考,同时作为博客文章的附件参考,大家可以访问我的博客,参考如何在OSX上编译libVLC版本
awesome-script:常用的shell脚本,包括centos,Ubuntu,Mac osx,以及Docker,Python等常用软件的安装,配置,开发环境构建的脚本
OSeXy是一个引导程序,旨在成为全新OSX安装上运行的第一个脚本。 它会: 检查系统更新安装Xcode命令行工具安装自制以及一些和设置从下载IE8,IE9和IE10 VM如何使用sh install.sh 免责声明OSeXy是一个WIP个人项目,...
一个简单的Bash脚本,使OpenSSL反向shell的生成变得无痛苦目录简介用法屏幕快照许可证简介Revssl的创建主要是为了使OpenSSL re自动化。创建它主要是为了从此处自动化OpenSSL反向Shell构想,并将其打包到一个脚本中。...
:用于安装全新OSX安装的shell脚本(基于)。 :加强安全性和隐私性的脚本(来自 ) osx-setup.sh概述 已安装和 安装冲泡配方和桶装位 Git和支持的应用程序(并配置git) 木桶钻头 其他酿造公式 安装Node和全局...
osx-init 在OS X的全新副本上安装软件并运行所需的脚本。 curl https://raw.githubusercontent.com/chcokr/osx-init/master/install.sh | sh
简单WebM OSX的非常简单的Shell脚本,可将视频转换为webm剪辑。 只需将剪辑拖放到图标上,即可将其转换为WebM视频(对于GAF而言是完美的)。 还包括带有自定义设置的脚本,用于设置: 自定义分辨率自定义CRF /质量...
#OSX Internet 连接共享,自动设置。 ##当前版本:1.7(测试版) 确保启用辅助设备访问(10.8 及更低版本)系统偏好设置 > 辅助功能 > 选中窗口底部的“启用辅助设备访问” 在较新的机器(10.9 及更高版本)上,将...
您将输入看起来像普通 shell 提示符的内容,但现在您可以开始运行 python 脚本并点击ctl+a让d屏幕 在后台运行。下次连接时,您可以使用 重新连接到屏幕会话screen -r。或 更多详情、使用方法,请下载后阅读README....