Mac OS X: 实用脚本程序(bash scripts)系列-9
2009-10-24 11:57
253 查看
Mac OS X: 实用脚本程序(bash scripts)系列-9
--添加应用程序icon到Dock
虽然说已经有了诸如lucidsystems的additemtodock
和dockutil
等多个管理Dock项的实用程序,(这里不涉及那些Dock花样的众多实用程序,有兴趣的可以参考这里
),下面的脚本很简单,它只是一个示例,缺少很多功能,比如它不能删除或者替换一个icon--其实这一点很容易实现;比如它不能添加folder或URL--这一点参考使用"persistent-others";再比如它只是对当前用户操作,这一点稍做修改也很容易扩展.
上面提到的两个实用程序,都无法对用户模版进行编辑,有些情况下对管理员来说就局限了,而对下面的程序稍加修改就可以做到。
使用:只要复制下面的内容到一个文件,变更文件属性可执行,那么就可以运行了。
#!/bin/bash # ----------------------------------------------------------------------- # A simple script to add application's icon to current user's Dock # # Name: addapptodock # # Operating System: # Tested on 10.4 and 10.5 # # 2009 Tony Liu # Copyright GNU GPL # Version 0.0.1 # # Version History # 0.0.1: 2009-10-23 Initial # ----------------------------------------------------------------------- # # Usage: see below, or run it in terminal. # num_argumnets=$# if [ "$num_argumnets" -lt "1" ] ; then echo "WARNING ! : No argument provided. Nothing added to the Dock." echo " Usage : addapptodock /Applications/Safari.app" exit 2 fi App_Name="$1" # --------------------------- # Check if it exists # --------------------------- App_Check=`defaults read com.apple.dock persistent-apps | grep -w '"_CFURLString" =' | grep -i "$App_Name"` if [ "${App_Check}" != "" ] ; then # This item is in the dock echo "WANRING! : Item <$App_Name> is already in the dock, it will not be added again." exit 1 fi # --------------------------- # Adding Application # --------------------------- if [ -d "$App_Name" ] || [ -f "$App_Name" ] ; then echo "Added <$App_Name>." defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$App_Name</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>" else echo "WARNING! : Could not locate Application <$App_Name>." fi killall Dock exit 0 |
相关文章推荐
- Mac OS X: 实用脚本程序(bash scripts)系列-7
- Mac OS X: 实用脚本程序(bash scripts)系列-5
- Mac OS X: 实用脚本程序(bash scripts)系列-6
- Mac OS X: 实用脚本程序(bash scripts)系列-13
- Mac OS X: 实用脚本程序(bash scripts)系列-7
- Mac OS X: 实用脚本程序(bash scripts)系列-5
- Mac OS X: 实用脚本程序(bash scripts)系列-6
- Mac OS X: 实用脚本程序(bash scripts)系列-13
- Mac OS X: 实用脚本程序(bash scripts)系列-8
- Mac OS X: 实用脚本程序(bash scripts)系列
- Mac OS X: 实用脚本程序(bash scripts)系列-2
- Mac OS X: 实用脚本程序(bash scripts)系列-3
- Mac OS X: 实用脚本程序(bash scripts)系列-11
- Mac OS X: 实用脚本程序(bash scripts)系列-8
- Mac OS X: 实用脚本程序(bash scripts)系列-6
- Mac OS X: 实用脚本程序(bash scripts)系列
- Mac OS X: 实用脚本程序(bash scripts)系列-2
- Mac OS X: 实用脚本程序(bash scripts)系列-3
- Mac OS X: 实用脚本程序(bash scripts)系列-11
- Mac OS X: 实用脚本程序(bash scripts)系列-10