Category Archives: OS

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:

UILabel linespacing issue when text is singleline

问题背景:

项目中经常需要给UILabel设置linespacing,但是在使用的过程中我们发现当我们设置linespacing,[label sizeToFit]后的高度会多出一个linespacing,严重影响布局

分析:

影响因素有很多:

  • font
  • UILabel.numberOfLines
  • paragraphStyle.lineBreakMode
  • UILabel.width
  • UILabel.text

这些变量的可能取值有:

systemFontOfSize

显式指定字体

单行(1)

有限制的多行(>1)

不限制行数(0)

NSLineBreakByTruncatingTail

NSLineBreakByCharWrapping

小于文本总宽度

大于等于文本总宽度

纯英文字符串

包含非英文字符串(中文,日文)

解决方法:

给label显式地指定字体

UIFont *titleFont = [UIFont fontWithName:@“PingFangSC-Regular” size:14];

不要使用

UIFont *titleFont = [UIFont systemFontOfSize:14];

 

参考链接:

http://stackoverflow.com/questions/32291105/line-spacing-for-uilabel-with-a-single-line-of-text

新的问题:

虽然上面的解决方法,使得[label sizeToFit]后的高度是准确的,无论numberOfLines是多少。但是我们经常需要给label一个最大宽度,那么问题来了。 当我们给label限制了最大宽度,且label.numberOfLines=1,此时如果label.text内容比较多,在限制的宽度下显示不完整,就会出现label渲染的时候没有垂直居中渲染文字,而是贴着label的顶部,底部留下间隙。如果在限制的宽度下,能显示完,也不存在这个问题

经过尝试,发现:

  1. paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;不存在这个问题,
  2. paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;有这个问题。

如果lineBreakMode = NSLineBreakByCharWrapping,就不会出现文本末尾“…”,视觉和产品可能不接受。。。

 

下面是实验对比截图:

页面中有两个UILabel实例,第一个label的numberOfLines=1,第二个label的numberOfLines=0。

 

图1. 未做任何处理,使用系统字体,sizeToFit的结果。多行的时候表现正常,一行的时候高度多了一个linespacing

Simulator Screen Shot 2016年7月14日 上午10.40.20

图2.  显式指定字体为苹方字体,sizeToFit后,表现都正常。Simulator Screen Shot 2016年7月14日 上午10.54.33

图3. 显式指定字体为苹方字体

UIFont *titleFont = [UIFont fontWithName:@”PingFangSC-Regular” size:14];

,sizeToFit后,label 的高度都是计算正确的,只不过,当我们再修改label.numberOfLines=1的label的width为比较小的值,出现渲染问题。

Simulator Screen Shot 2016年7月14日 上午11.13.51 

总结:

 

  1. 当我们已经从需求来源明确了label的numberOfLines=1,不能给label设置linespacing
  2. 当我们确定label的numberOfLines 不为1,如果需要给label设置linespacing的话,请一定要显式的给它设置字体,不要使用[UIFont systemFontOfSize:14]这种方式给它设置字体,其实就是给attributedText设置字体。

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