Tag Archives: MacOS

change default application open files mac os x

from:

Mac上全局设置文件的默认打开程序

http://osxdaily.com/2013/08/08/change-default-application-open-files-mac-os-x/

清空打开文件context menu的选项

http://osxdaily.com/2013/01/22/fix-open-with-menu-mac-os-x/

 

1: Set the Default Application for a Specific File in Mac OS X

This provides file-specific control over default applications, meaning you can have a document or two that open in one app, while the overall general file type defaults to open in another application. For example, you could set one single PSD file to always open exclusively in Pixelmator, while all other PSD formatted documents continue to open in Adobe Photoshop.

  1. From the OS X Finder, right-click (or Control+Click) on the file to change the default app for and hold down the OPTION key so that the “Open With” menu becomes “Always Open With”
  2. Continue to hold OPTION and select the application you want to set as the default for this file

Set the default application for a file in Mac OS X

The file will open in the application you selected, and that file will now associate the chosen application as it’s new default to always open within.

By the way, if you’re setting a file type this way and notice duplicate entries in that Open With menu, you can remove those duplicate entries with this quick trick to clean up the Open With contextual menu.

Again, this is specific to the file you chose, and this method will not apply to all files sharing that same file format. If you want to set the default application universally for a file type, that’s what the next tip is for.

2: How to Set Default Applications to Open All Files of a Format Type in Mac OS X

This approach will change the default application universally for all files of a specific format. For example, you could use this to set all files of the type PNG to open within Skitch, all TXT files to open with TextWrangler, and all ZIP files to open with The Unarchiver.

    1. From the Mac file system, select a file of the general format type you wish to change the default application for
    2. Pull down the “File” menu and choose “Get Info” (or hit Command+i) to access the Get Info window
    3. Click the “Open with:” sub menu, then click on the contextual menu and select the new application to associate all files of this format type with

Change the default application for all files of a format to be associated with

    1. Click the “Change All” button and confirm the change when requested

Change All files of a type to always open with the set application

  1. Close out of Get Info, repeat for other file format types if necessary

(Note: if the Change All button is greyed out and unclickable it’s because you have not set an application that is different than the currently set default app. Use the pulldown menu to choose the new application for the Change All button to be usable and to apply the adjustment to all files of the file format type)

This change carries throughout all files of that format used within Mac OS X for the active user account, and the filetype-to-application association will stay in place until it has been changed again through the same “Get Info” trick, or until a third party application claims the file format and associates with it directly.

You’ll find this one particularly useful if a newly installed application has assumed control over a file format, like what often happens with Adobe Reader claiming all PDF documents. This ‘Change All‘ trick will allow you to quickly reclaim PDF file types to reopen again in Preview (or your app of choice), which is typically much faster than launching such files in more resource heavy apps like Reader.

The video below demonstrates the latter trick, changing the default application for all files of a given type:

Finder plugin “cd-to”

http://www.tuicool.com/articles/MbaQNv

 

Posted on December 5, 2012 by in Tools

 

Mac Tips For iOS Developers

In a previous post I mentioned iTerm2 as a Mac OS X terminal replacement . Hopefully you’ve taken the time to check it out. If so, and you appreciate all it has to offer, the next step is to find a means to easily open iTerm2.

I have a number of scripts (Applescript code) that I have written and saved as applications. I then add the application to the toolbar in Finder. My toolbar looks as follows, all of the icons in the green box I’ve added:

Let me walk you through the steps to create a script that will open a new iTerm2 window and change to the current Finder path. I’ll also show you how to create an icon for the application so it is easy to recognize in Finder.

First, open up the AppleScript Editor and copy/paste the code below (code courtesy Stefan van den Oord):

-- Stefan van den Oord, 2010-12-29
-- The "cd to" command for iTerm2
 
tell application "Finder"
  set _cwd to POSIX path of ((folder of (front window)) as alias)
end tell
 
tell application "iTerm2"
  activate
 
  try
    set _session to current session of current terminal
  on error
    set _term to (make new terminal)
    tell _term
            launch session "Default"
            set _session to current session
    end tell
  end try
 
  tell _session
    write text "pushd \"" & _cwd & "\""
  end tell
end tell

– Save the file as an application.

Before we drag/drop the application onto Finder, let’s create an icon for the application.

– Go to Iterm2 and use the Mac copy to clipboard feature (shift-command-4) to copy the logo.

– Open the screenshot in Preview, mark the image (control-a) and copy to clipboard (control-c).

– Find the application you saved above, right click and select Get Info .

– Tap the icon in the upper left corner and paste the saved image (control-v).

You now have Applescript that has been saved as an application, with a shiny new icon.

The final step is to drag the application onto the Finder toolbar.

You are good to go, iTerm2 at the current Finder path, one click away.

 

 

 

==============

see other solutions

 

http://stackoverflow.com/questions/420456/open-terminal-here-in-mac-os-finder

System Integrity Protection On Mac OS X EI Capitan

http://apple.stackexchange.com/questions/193368/what-is-the-rootless-feature-in-el-capitan-really

当我们在EI Capitan上安装 CocoaPods的时候,安装完成后,运行pod命令时,老是报错: pod command not fund!

只有我们重新安装pod,并显式地指定安装目录,才解决这个问题,原因就是EI Capitan不允许用户修改部分系统文件夹,比如/System,/bin等,即使使用sudo。具体原因请参考:http://apple.stackexchange.com/questions/193368/what-is-the-rootless-feature-in-el-capitan-really

 

 

 

 

8个不可不知的Mac OS X专用命令行工具

 

原文:

http://www.mitchchn.me/2014/os-x-terminal/

译文:

http://segmentfault.com/a/1190000000509514

An A-Z Index of the Apple OS X command line

http://ss64.com/osx/

OS X的终端下通用很多Unix的工具和脚本。如果从Linux迁移到OS X会发现很多熟悉的命令和脚本工具,其实并没有任何区别。

但是OS X也提供了很多其他系统所没有的特别的命令行工具。我们推荐8个这类的工具,希望有助于提高在Mac的命令行环境下的效率。

1. open

open命令用于打开文件、目录或执行程序。就等同于在命令行模式下,重复图形界面“双击”的动作。例如这个命令与在Finder中双击Safari是一样的:

$ open /Applications/Safari.app/

如果open一个文件,则会使用关联的程序打开之。例如open screenshot.png会在Preview中查看图片。

可以使用-a选项要求自行选择打开的程序,或使用-e强制在TextEdit中编辑此文件。

open一个目录会在Finder窗口中打开此目录。一个很有用的技巧是open .打开当前目录。

Finder和终端的交互是双向的——把文件从Finder中拖入终端,就等同于把文件的完整路径粘贴到命令行中。

2. pbcopy 和 pbpaste

这两个工具可以打通命令行和剪贴板。当然用鼠标操作复制粘贴也可以——但这两个工具的真正威力,发挥在将其用作Unix工具的时候。意思就是说:可以将这两个工具用作管道、IO重定向以及和其他命令的整合。例如:

$ ls ~ | pbcopy

可以将主目录的文件列表复制到剪贴板。

也可以把任意文件的内容读入剪贴板:

$ pbcopy < blogpost.txt

做点更疯狂的尝试:获取最新Google纪念徽标(doodle)的URL并复制到剪贴板:

$ curl http://www.google.com/doodles#oodles/archive | grep -A5 'latest-doodle on' | grep 'img src' | sed s/.*'<img src="\/\/'/''/ | sed s/'" alt=".*'/''/ | pbcopy

使用管道语法配合pbcopy工具可以简单的抓取命令的输出,而不必向上滚动翻阅终端窗口。可以用于和他人分享命令行的标准和错误输出。pbcopypbpaste也可以用于自动化或加速执行一些事情。例如把一些邮件的主题存为任务列表,就可以先从Mail.app中复制主题,再运行:

$ pbpaste >> tasklist.txt

3. mdfind

许多Linux用户都发现Linux下查找文件的方法在OS X上不好用。当然经典的Unix find命令总是可以,但既然OS X有杀手级搜索工具Spotlight,为什么不在命令行上也使用一下呢?

这就是mdfind命令了。Spotlight能做的查找,mdfind也能做。包括搜索文件的内容和元数据(metadata)。

mdfind还提供更多的搜索选项。例如-onlyin选项可以约束搜索范围为一个目录:

$ mdfind -onlyin ~/Documents essay

mdfind的索引数据库在后台自动更新,不过你也可以使用mdutil工具诊断数据库的问题,诊断mdfind的问题也等同于诊断Spotlight。如果Spotlight的工作不正确,mdutil -E命令可以强制重建索引数据库。也可以用mdutil -i彻底关闭文件索引。

4. screencapture

screencapture命令可以截图。和Grab.appcmd + shift + 3cmd + shift + 4热键相似,但更加的灵活。

抓取包含鼠标光标的全屏幕,并以image.png插入到新邮件的附件中:

$ screencapture -C -M image.png 

用鼠标选择抓取窗口(及阴影)并复制到剪贴板:

$ screencapture -c -W

延时10秒后抓屏,并在Preview中打开之:

$ screencapture -T 10 -P image.png

用鼠标截取一个矩形区域,抓取后存为pdf文件:

$ screencapture -s -t pdf image.pdf

更多用法请参阅screencapture --help

5. launchctl

launchctl管理OS X的启动脚本,控制启动计算机时需要开启的服务。也可以设置定时执行特定任务的脚本,就像Linux cron一样。

例如,开机时自动启动Apache服务器:

$ sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

运行launchctl list显示当前的启动脚本。sudo launchctl unload [path/to/script]停止正在运行的启动脚本,再加上-w选项即可去除开机启动。用这个方法可以一次去除Adobe或Microsoft Office所附带的所有“自动更新”后台程序。

Launchd脚本存储在以下位置:

~/Library/LaunchAgents    
/Library/LaunchAgents          
/Library/LaunchDaemons
/System/Library/LaunchAgents
/System/Library/LaunchDaemons

启动脚本的格式可以参考这篇blog,或苹果开发者中心的文章。你也可以使用Lingon应用来完全取代命令行。

6. say

say是一个文本转语音(TTS)的有趣的工具,引擎和OS X使用的一样也是VoiceOver。如果不加其他选项,则会简单的语音朗读你给定的字符串:

$ say "Never trust a computer you can't lift."

-f选项朗读特定文本文件,-o选项将朗读结果存为音频文件而不是播放:

$ say -f mynovel.txt -o myaudiobook.aiff

say命令可以用于在脚本中播放警告或提示。例如你可以设置Automator或Hazel脚本处理文件,并在任务完成时用say命令语音提示。

最好玩(不过也负罪感十足)的用法是:通过SSH连接到朋友或同事的计算机,然后用say命令给他们一个大大大惊喜……

可以在系统设置(System Preferences)的字典和语音(Dictation & Speech)选项中调整系统的语音选项甚至是语音的语言。

7. diskutil

diskutil是OS X磁盘工具应用的命令行版。既可以完成图形界面应用的所有任务,也可以做一些全盘填0、全盘填随机数等额外的任务。先使用diskutil list查看所有磁盘的列表和所在路径,然后对特定的磁盘执行命令。

警告:不正确使用diskutil可能意外的破坏磁盘数据。请小心。

8. brew

Homebrew程序提供的brew,严格来讲不是一个OS X的原生命令,但任何一个OS X的专业用户都不会错过它。“OS X缺少的包管理器”这个评价是恰如其分的。如果你曾经在Linux上使用过apt-get(或其他包管理器——译者注),你就会发现Homebrew基本上是一样的。

使用brew可以简单的获取数千种开源工具和函数库。例如brew install imagemagick就可以安装ImageMagick(几乎可以处理任何图像问题,转换任何格式的图像工具),brew install node可以安装Node.js(当前大热的服务器端JavaScript编程工具)。

也可以通过Homebrew做有趣的事情:brew install archey会安装Archey(在启动命令行时显示苹果LOGO和计算机硬件参数的小工具)。

Homebrew能安装的工具数量庞大,并且一直保持更新。Homebrew最棒的一点是:所有的文件都被约束在/usr/local/一个位置之下。也就是说可以通过Homebrew安装新版软件的同时,保持系统内置的依赖库或其他软件不变。同时如果想彻底删除Homebrew,也变得非常简单。

(注:删除Homebrew最好还是不要直接删除/usr/local/。应当用这个卸载脚本。)

最后,这里还有一篇OS X所有命令的完整列表


8个不可不知的Mac OS X专用命令行工具
原文:Eight Terminal Utilities Every OS X Command Line User Should Know
编译:SegmentFault
责任:沙渺