🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### Mac OS X: 实用脚本程序(bash scripts)系列-9 ### --添加应用程序icon到Dock    虽然说已经有了诸如lucidsystems的[additemtodock](http://www.lucidsystems.org/luciddocktools.html "Add Item to Dock")和[dockutil](http://code.google.com/p/dockutil/ "DockUtil")等多个管理Dock项的实用程序,(这里不涉及那些Dock花样的众多实用程序,有兴趣的可以[参考这里](http://search.macupdate.com/search.php?keywords=Dock&os=mac "Mac Update")),下面的脚本很简单,它只是一个示例,缺少很多功能,比如它不能删除或者替换一个icon--其实这一点很容易实现;比如它不能添加folder或URL--这一点参考使用"persistent-others";再比如它只是对当前用户操作,这一点稍做修改也很容易扩展.       上面提到的两个实用程序,都无法对用户模版进行编辑,有些情况下对管理员来说就局限了,而对下面的程序稍加修改就可以做到。       使用:只要复制下面的内容到一个文件,变更文件属性可执行,那么就可以运行了。   <table id="y5eg" style="width: 100%;" border="1" cellspacing="0" cellpadding="3" bordercolor="#000000"><tbody><tr><td width="100%"><p>#!/bin/bash<br/><br/># -----------------------------------------------------------------------<br/># A simple script to add application's icon to current user's Dock<br/>#<br/># Name: addapptodock<br/># <br/># Operating System:<br/>#    Tested on 10.4 and 10.5<br/>#<br/># 2009 Tony Liu</p><p># Copyright GNU GPL<br/># Version 0.0.1<br/>#<br/># Version History<br/>#    0.0.1: 2009-10-23 Initial<br/># -----------------------------------------------------------------------<br/><br/>#<br/># Usage: see below, or run it in terminal.<br/>#<br/>num_argumnets=$#<br/>if [ "$num_argumnets" -lt "1" ] ; then<br/>    echo "WARNING ! : No argument provided. Nothing added to the Dock."<br/>    echo "            Usage : addapptodock /Applications/Safari.app"<br/>    exit 2<br/>fi<br/><br/>App_Name="$1"<br/><br/># ---------------------------<br/># Check if it exists<br/># ---------------------------<br/>App_Check=`defaults read com.apple.dock persistent-apps | grep -w '"_CFURLString" =' | grep -i "$App_Name"`<br/>if [ "${App_Check}" != "" ] ; then<br/>    # This item is in the dock<br/>    echo "WANRING! : Item &lt;$App_Name&gt; is already in the dock, it will not be added again."<br/>    exit 1<br/>fi<br/><br/># ---------------------------<br/># Adding Application<br/># ---------------------------<br/>if [ -d "$App_Name" ] || [ -f "$App_Name" ] ; then<br/>    echo "Added &lt;$App_Name&gt;."<br/>   defaults write com.apple.dock persistent-apps -array-add"&lt;dict&gt;&lt;key&gt;tile-data&lt;/key&gt;&lt;dict&gt;&lt;key&gt;file-data&lt;/key&gt;&lt;dict&gt;&lt;key&gt;_CFURLString&lt;/key&gt;&lt;string&gt;$App_Name&lt;/string&gt;&lt;key&gt;_CFURLStringType&lt;/key&gt;&lt;integer&gt;0&lt;/integer&gt;&lt;/dict&gt;&lt;/dict&gt;&lt;/dict&gt;"       <br/>else<br/>    echo "WARNING! : Could not locate Application &lt;$App_Name&gt;."<br/>fi<br/><br/>killall Dock<br/><br/>exit 0</p></td></tr></tbody></table>