罗技 Logi MX 系列键盘布局切换方法

本方法适用于所有 MX 系列键盘,非 MX 系列没有尝试,不保证可用。

罗技的 MX 系列键盘通常有两个布局模式,最主要的区别就在于底部的 start 按键和 alt 按键。

通过按键的标记可以看到,start 键(即 Windows 徽标键)在 mac 布局下是 opt 键,而 alt 键在 mac 布局下是 cmd 键。

但是这里的按键布局,翻遍了说明都没有找到如何切换。通过搜索发现,跟键盘第一次连接的设备有关。如果键盘第一次连接 mac,则使用左侧的 mac 布局。如果连接的是 Windows,则使用右侧的 Windows 布局。

这导致对双系统用户极度不友好。切换系统时,会出现按键标记与实际功能不符的情况。于是经过多方搜索,找到了手动切换布局的方法:

切换到 Windows 布局:按住 FN + P 键 3 秒(Hold FN+P for 3 seconds)

切换到 mac 布局:按住 FN + O 键 3 秒(Hold FN+O for 3 seconds)

新版 Mac U 盘重装系统的注意事项

由于苹果在新版的 Mac 中内置了 T2 安全芯片,因此当我们在下面这些版本的 Mac 上尝试使用 U 盘重装系统的时候,需要额外注意。

本文章适用的 Mac 型号包括:

主要注意的核心点是:

  1. 不要先格式化硬盘
  2. 不要先删除原系统中的管理员用户
  3. 切记先进 Recovery 模式修改安全芯片选项,再开始重装
  4. 最好先升级到最新的系统再重装

说说原因:

  1. 如果先格式化硬盘,Recovery 模式无法找到有效的管理员账号,不允许修改 T2 芯片的选项
  2. 同 1,删除所有管理员账户会导致无法修改选项
  3. 将安全芯片选项修改为 No Security + Allow booting from external media 之后,再进行重装,防止重装操作被安全芯片拦截。
  4. 遇到很多诡异的问题就算将安全芯片选项修改了也不生效。但是有时候又是生效的。所以最好升级到最新的啦

https://support.apple.com/en-us/HT208330

减少 Mac – Office365 网络请求和流量

在功能和使计算机保持最新状态这两个方面,Office 2016 for Mac 的默认配置提供了最佳用户体验。

在某些情况下,可能希望阻止应用程序联系网络终结点。

若要防止应用程序发送“使用情况”遥测可从终端手动设置:

defaults write com.microsoft.WordSendAllTelemetryEnabled -bool FALSE
defaults write com.microsoft.WordSendAllTelemetryEnabled -bool FALSE
defaults write com.microsoft.ExcelSendAllTelemetryEnabled -bool FALSE
defaults write com.microsoft.PowerpointSendAllTelemetryEnabled -bool FALSE
defaults write com.microsoft.OutlookSendAllTelemetryEnabled -bool FALSE
defaults write com.microsoft.onenote.mac SendAllTelemetryEnabled -bool FALSE
defaults write com.microsoft.autoupdate2 SendAllTelemetryEnabled -bool FALSE
defaults write com.microsoft.Office365ServiceV2 SendAllTelemetryEnabled -bool FALSE
defaults write com.microsoft.WordSendASmileEnabled -bool FALSE
defaults write com.microsoft.ExcelSendASmileEnabled -bool FALSE
defaults write com.microsoft.PowerpointSendASmileEnabled -bool FALSE
defaults write com.microsoft.OutlookSendASmileEnabled -bool FALSE
defaults write com.microsoft.onenote.mac SendASmileEnabled -bool FALSE
defaults write com.microsoft.errorreportingIsAttachFilesEnabled -bool FALSE

(Copy以上命令行,打开 Mac – 终端,粘贴进去,回车就行了。已包含反馈调查和故障报告)

禁用说明:

遥测

Office 2016 for Mac 会定期将遥测信息发送回 Microsoft。

向“Nexus”终结点上传数据。

遥测数据可帮助工程团队评估每个 Office 应用的运行状况和任何意外行为。

遥测分为两类:

Ø 检测信号包含版本和许可证信息。应用启动时此数据会立即发送。

Ø 使用情况包含应用的使用情况和不严重的错误。此数据每 60 分钟发送一次。

注意:检测信号将始终发送遥测,无法禁用。

 

反馈和调查

使用 Office 2016 for Mac 有可能需要提供 Office 体验反馈。

微软根据反馈内容不断改进产品、了解新功能请求和评估客户对产品改动的满意度。

反馈分为两种类别:用户反馈和调查。

Ø 用户反馈由 Office 使用者发起。他们可以提交评论,或者可选择提供屏幕截图和电子邮件地址。

Ø 调查由 Office 发起,显示为可关闭的通知消息。可以提交评分,同时可选择提交评论。每 3 个月最多请求 1 次调查。

可以在 Office 中基于每个应用程序禁用反馈和调查。

 

故障报告

应用程序出现严重错误时,该应用程序将意外终止并将故障报告上传到“Watson”服务。

故障报告包括一个调用堆栈,它是应用程序所处理并导致故障的步骤列表。

这些步骤可帮助微软工程团队确定失败的确切函数以及原因。

在某些情况下,文档的内容将导致应用程序出现故障。

如果应用将文档标识为原因,它会询问用户是否可以将文档与调用堆栈一起发送。

用户可以在了解信息的情况下对此问题作出选择。

为防止发送文档并禁止向用户显示提示

修复 Mac OS X 新版 Terminal 在 SSH 时候出现的 LANGUAGE WARNING

自从升级了新版的 Mac OS X 之后,使用 Terminal SSH 到别的机器上总是能看到这样的警告:

-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

在执行 perl 脚本的时候还能看到这样的警告:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

找了很多方法,包括改服务端 sshd config 什么的,都觉得不好。因为这应该不是服务端的问题,不应该在服务端解决。于是仔细搜索之后发现这个回答完美解决了这个问题:

http://stackoverflow.com/questions/2499794/how-can-i-fix-a-locale-warning-from-perl/7413863#7413863

Here is how to solve it on Mac OS Lion (10.7):

Add the following lines to your bashrc or bash_profile on the host machine:

# Setting for the new UTF-8 terminal support in Lion
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

If you are using zsh, edit zshrc:

# Setting for the new UTF-8 terminal support in Lion
LC_CTYPE=en_US.UTF-8
LC_ALL=en_US.UTF-8

Git 统计代码量

最近有一个需求是要统计 Git 仓库里每个人的代码量,于是上网搜了一下,找了一些相关命令:

指定用户名版

git log --author="_Your_Name_Here_" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -

这句话可以输出当前项目内指定用户名的用户的代码量统计,结果如下:

added lines: 30400 removed lines: 21317 total lines: 9083

使用 ls-file 实现不指定用户版统计行数版

git ls-files -z | xargs -0n1 git blame -w | ruby -n -e '$_ =~ /^.*\((.*?)\s[\d]{4}/; puts $1.strip' | sort -f | uniq -c | sort -n

这段代码比较有意思,它扫描了当前分支的每个文件,然后用 Git 的 blame 功能输出每个人的代码行数,最后用系统命令 sort 和 uniq 实现计数。

结果如下:

   8 aaa
   9 bbb
 145 ccc
 146 ddd
 261 eee

扫描 Log 统计增删行数版

git log --shortstat --pretty="%cE" | sed 's/\(.*\)@.*/\1/' | grep -v "^$" | awk 'BEGIN { line=""; } !/^ / { if (line=="" || !match(line, $0)) {line = $0 "," line }} /^ / { print line " # " $0; line=""}' | sort | sed -E 's/# //;s/ files? changed,//;s/([0-9]+) ([0-9]+ deletion)/\1 0 insertions\(+\), \2/;s/\(\+\)$/\(\+\), 0 deletions\(-\)/;s/insertions?\(\+\), //;s/ deletions?\(-\)//' | awk 'BEGIN {name=""; files=0; insertions=0; deletions=0;} {if ($1 != name && name != "") { print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net"; files=0; insertions=0; deletions=0; name=$1; } name=$1; files+=$2; insertions+=$3; deletions+=$4} END {print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net";}'

这段比较复杂,我也没有认真解读,直接贴结果吧:

aaa,: 353 files changed, 9359 insertions(+), 3844 deletions(-), 5515 net
aaa,bbb,: 4 files changed, 144 insertions(+), 2 deletions(-), 142 net
ccc,: 114 files changed, 2301 insertions(+), 481 deletions(-), 1820 net
ddd,: 27 files changed, 1856 insertions(+), 757 deletions(-), 1099 net
eee,: 1726 files changed, 32841 insertions(+), 22719 deletions(-), 10122 net
eee,fff,: 13 files changed, 209 insertions(+), 211 deletions(-), -2 net
ggg,: 53 files changed, 1153 insertions(+), 1170 deletions(-), -17 net
fff,: 2445 files changed, 69875 insertions(+), 62148 deletions(-), 7727 net
fff,eee,: 30 files changed, 394 insertions(+), 472 deletions(-), -78 net
bbb,: 37 files changed, 781 insertions(+), 216 deletions(-), 565 net
hhh,: 4 files changed, 34 insertions(+), 4 deletions(-), 30 net

比较奇怪的是会列出两个人同时修改,可能是 merge 操作,没有深究。

扫描 Log 单独统计每个人的增删行数加强版

git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done

直接上输出:

aaa	added lines: 34, removed lines: 4, total lines: 30
bbb	added lines: 2301, removed lines: 481, total lines: 1820
ccc	added lines: 1856, removed lines: 757, total lines: 1099
ddd	added lines: 30400, removed lines: 21317, total lines: 9083
eee	added lines: 1153, removed lines: 1170, total lines: -17
fff	added lines: 1153, removed lines: 1170, total lines: -17
ggg	added lines: 72886, removed lines: 64233, total lines: 8653
hhh	added lines: 814, removed lines: 216, total lines: 598
iii	added lines: 9503, removed lines: 3846, total lines: 5657

第三方小工具版

使用这个工具可以直接输出非常漂亮的统计表格:

https://github.com/oleander/git-fame-rb

gem install git_fame
cd /path/to/gitdir && git fame
Total number of files: 2,053
Total number of lines: 63,132
Total number of commits: 4,330

+------------------------+--------+---------+-------+--------------------+
| name                   | loc    | commits | files | percent            |
+------------------------+--------+---------+-------+--------------------+
| Johan Sørensen         | 22,272 | 1,814   | 414   | 35.3 / 41.9 / 20.2 |
| Marius Mathiesen       | 10,387 | 502     | 229   | 16.5 / 11.6 / 11.2 |
| Jesper Josefsson       | 9,689  | 519     | 191   | 15.3 / 12.0 / 9.3  |
| Ole Martin Kristiansen | 6,632  | 24      | 60    | 10.5 / 0.6 / 2.9   |
| Linus Oleander         | 5,769  | 705     | 277   | 9.1 / 16.3 / 13.5  |
| Fabio Akita            | 2,122  | 24      | 60    | 3.4 / 0.6 / 2.9    |
| August Lilleaas        | 1,572  | 123     | 63    | 2.5 / 2.8 / 3.1    |
| David A. Cuadrado      | 731    | 111     | 35    | 1.2 / 2.6 / 1.7    |
| Jonas Ängeslevä        | 705    | 148     | 51    | 1.1 / 3.4 / 2.5    |
| Diego Algorta          | 650    | 6       | 5     | 1.0 / 0.1 / 0.2    |
| Arash Rouhani          | 629    | 95      | 31    | 1.0 / 2.2 / 1.5    |
| Sofia Larsson          | 595    | 70      | 77    | 0.9 / 1.6 / 3.8    |
| Tor Arne Vestbø        | 527    | 51      | 97    | 0.8 / 1.2 / 4.7    |
| spontus                | 339    | 18      | 42    | 0.5 / 0.4 / 2.0    |
| Pontus                 | 225    | 49      | 34    | 0.4 / 1.1 / 1.7    |
+------------------------+--------+---------+-------+--------------------+

 

How to Start the Mac Screen Saver with a Keyboard Shortcut in OS X

start-screen-saver-keystroke-mac

Have you ever wanted to initiate the screen saver of your Mac by hitting a keystroke combination? You’re not alone, and that’s what we’re going to show you how to do here. While OS X does not include this feature by default, we’ll demonstrate how to create an Automator system service that will accomplish the same feat, activating the screen saver by a keyboard shortcut of your choosing.


To be clear, this service will start the default screen saver, meaning whatever has been selected in the Desktop & Screen Saver preference panel, accessible from the  Apple menu and System Preferences. If you want to change the screen saver used by this, simply change it there. For best results, use the screen saver with general password protection too, which will let the keystroke be used as a way to protect the Mac when you’re away from the keyboard or desk.

Part 1: Create a Screen Saver Automator Service for OS X

    1. Launch Automator, found in the /Applications/ directory
    2. Choose to create a new “Service”

create-new-service-automator

    1. Use the search box to find “Start Screen Saver” and drag that into the right side panel
    2. Change “Service receives” to “no input”

make-screen-saver-service-automator-mac

    1. Go to the File menu and choose “Save” naming it something obvious like “Start Screen Saver”

save-screen-saver-keystroke-service

Now that you have created a service that starts the default screen saver, you need to assign a keystroke combination to initiate the service. Be sure to pick a keyboard shortcut that is unique and easy to remember.

Part 2: Set the “Start Screen Saver” Keystroke for Mac OS X

    1. Open System Preferences from the  Apple menu
    2. Choose the “Keyboard” preference panel then go to the “Shortcuts” tab
    3. Select “Services” from the left side menu
    4. Locate the newly created “Start Screen Saver” service you made, and click on the ‘add shortcut’ button to set your keyboard shortcut to use – in this example we used Control+Command+Option+Down Arrow but you can set whatever you want

set-keystroke-for-screensaver-mac

  1. Exit out of System Preferences and test out your new screen saver keystroke

You can try it out by hitting the set keyboard shortcut sequence, which will now initiate the screen saver immediately.

keystroke-for-screen-saver-mac-610x350

To use this as a variation of the lock screen trick that doesn’t sleep the Mac display, be sure you have set a locked screen password and required the password be used to wake the Mac from a screen saver. That’s handled in the Security & Privacy preference panel under the “General” tab.

Keep in mind you can always use hot corners to start the Mac screen saver too, which for some individuals may be faster and easier to remember than a keystroke, since you simply need to slide the cursor into one of the far screen edges to initiate a hot corner.

How to Change the Profile Picture of a Mac User Account

The first time you set up a Mac or new user account, you’re asked to pick a profile picture for that account. Most of us set this image once and don’t think much about it, but that profile picture follows us around in OS X and is visible at each boot login menu, in the Fast User Switching menu, visible to other users with AirDrop, and plenty of other places in Mac OS X.

If you decide you want to change that user profile picture, perhaps to a more generic image, a mugshot, or a custom photo, you can do so at any time, and for any user account on the Mac. We’ll show you two ways to do this.

Changing a User Profile Picture in Mac OS X

    1. Open System Preferences from the  Apple menu and then select “Users & Groups” from the panel list
    2. Select the user account to change from the left side (choose the current user to change your own), you must have admin privileges to change other users profile pictures
    3. Click the current profile picture to pull down a list of options, select any of the following:

change-profile-pic-mac-user

      • Defaults – the Apple included profile picture choices
      • Recents – recently used profile photos (if you’ve changed it before, they will be listed here)
      • iCloud – photos from iCloud will show up here, including pictures taken with the iPhone
      • Faces – pictures identified as faces by iPhoto or Aperture
      • Camera – opens the FaceTime Camera to take a new picture

change-user-profile-picture-mac-default-choices

  1. Choose an image, adjust if desired, then click “Done” to set as the new profile picture
  2. Close out of System Preferences

Using a Custom Image or Photo as the Profile Picture in Mac OS X

The first approach let’s you choose from either a variety of Apple bundled default options, iCloud pictures, and the FaceTime camera, but what if you have an image file you want to use as the profile picture instead? That’s also easy to change, you can do it with a simple drag and drop:

  1. Open the “Users & Groups” preference panel as usual
  2. Drag and drop an image file into the existing profile picture thumbnail
  3. Adjust as necessary and click “Done” to set the image as the profile picture

Dragging and dropping works best from a Finder window, like so:

drag-drop-to-change-profile-pic-mac-user

You can use the little slider tool to both crop or zoom in and out on the picture, choosing “Done” sets the changed image as the profile picture for that Mac user.

choose-done-to-set-new-profile-pic-mac

Close out of System Preferences and go about your business, that’s all there is to it.

Remember that the profile picture is broadcasted to the world on AirDrop, so for users in public environments, you may want to aim for a boring and professional image.

This can also be a good trick to make a customized guest user account much more obvious, since by default the guest user it’s just a blank face image.

Maintain & Recall Command Line Clipboard History with iTerm 2

iterm2-icon

Mac users who spend a lot of time at the command line have yet another reason to use iTerm 2 as their default terminal client; clipboard history. Added in the most recent version of iTerm, a running history of OS X clipboard activity can be natively stored, recalled, and summoned directly in iTerm2, accessible through a handy new feature panel called Toolbelt.


You’ll need the latest version of iTerm 2 (you can grab the newest version here) to have access to the Toolbelt and Paste History features, then you just need to launch iTerm 2 and hit Command+Shift+B to summon the tool belt. Be sure the ‘Paste History’ option is enabled in Toolbelt menu to have the feature visible with a simple keystroke toggle.

command-line-clipboard-history-iterm2

Choosing any Paste History entry will immediately re-enter the syntax where ever the prompt is located.

The clipboard history doesn’t just store commands, it stores everything bound to the clipboard (including entries from pbcopy), making it perfect for holding onto everything from lengthy commands to code snippets and IP addresses. Sure, there are some great third party utilities like ClipMenu that will keep a running tally of all clipboard activity in OS X and have it accessible through a menu bar item, but as heavy command line users know, having easy access to things without leaving the task at hand can be absolutely critical to maintaining workflow.

Separately, you’ll also find the new Toolbelt feature of iTerm2 includes a handy little notes sheet, a profile manager, and a very nice jobs/process manager complete with signal sending. So while the occasional command line user may get by fine with using the default Terminal app bundled with OS X, power users will continue to find immense value in iTerm2 with it’s speed and myriad of advanced features.

Ctrl与Caps Lock键的交换

Emacs和VIM之所以这样受程序员的喜爱,是因为两者都有高度的可定制性,以及丰富的快捷键组合。利用这些快捷键组合,让你能够手不离键盘,就能完成大多数的工作。其实,用鼠标操作神马的,效率是极其低下的……

话说Emacs中,用到最多的两个快捷键组合,就是Meta键和Ctrl键。对于我们普通的键盘,Meta键还好,离手很近。不过,对于Ctrl键,就离得比较远了…… 网上有网友推荐的做法,是用手掌去按Ctrl键,不过,这样的方法,对于普通键盘还不错,但是对于笔记本来说,也不太实用。

正规的Unix键盘的键位布局,Ctrl键应该是在现在标准键盘的Caps Lock位置的。这样,按起Ctrl键,就方便多了。

那要怎么交换这两个键的键位呢?重新买一个键盘? No!! 其实,也不用换键盘,我们完全可以用软件的方式来实现两个键位的交换。
下面是我从网上整理来的方法:

Win7下交换键位的设置

其实Win7下面,方法还比较多,一种是直接修改注册表,实现全局的替换,另外一种,是让两个键的交换,只在Emacs窗口激活的时候生效。至于哪个更好,完全根据你自己的需要。

局部替换大法

这种方法,需要用到一个辅助软件,那就是大名鼎鼎的Auto Hotkey,简称AHK

编辑一个脚本,输入如下内容,保存,reload,即可生效:
IfWinActive emacs; 判断当前激活的窗口是否是Emacs,这是根据窗口标题实现的,如果你的标题不一样,请替换一下

Control::Capslock; 把Control替换为Capslock

Capslock::Control; 把Capslock替换为Control

IfWinActive

全局替换大法

可以利用第三方工具,或者直接在注册表中修改键位映射关系

注册表位置:[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout] 如果没有此键,就新建一个

新建一个二进制值的Key,名叫:Scancode Map

输入如下的值:

00,00,00,00

00,00,00,00

03,00,00,00

3A,00,1D,00

1D,00,3A,00

00,00,00,00

前两行和最后一行,都是固定的,全部为0。第三行,表示你修改了几个键,其实我们只是改了两个键,不过最后那一行也要算进去,所以是3。

重点是在第四行和第五行。3A00,代表Caps Lock, 1D00,代表Ctrl。这一行,意思即为,将Caps Lock映射为Ctrl

第五行,就不用说了,意思刚好相反。

修改完毕后,重新登录Windows即可生效!

下面附上各个键位值的参考:

Escape 01 00

Tab 0F 00

Caps Lock 3A 00

Left Alt 38 00

Left Ctrl 1D 00

Left Shift 2A 00

Left Windows 5B E0

Right Alt 38 E0

Right Ctr l1D E0

Right Shift 36 00

Right Windows 5C E0

Backspace 0E 00

Delete 53 E0

Enter 1C 00

Space 39 00

Insert 52 E0

HOME 47 E0

End 4F E0

Num Lock 45 00

Page Down 51 E0

Page Up 49 E0

Scroll Lock 46 00

Mac OS下交换键位设置

Mac OS Lion下,非常简单,甚至不需要任何第三方软件,直接在键盘设置里面修改即可。当初我还google了一下文章,有的说需要装键盘驱动,有的说要用第三方软件,其实没那么麻烦,Lion已经有这个功能了……

git commit 出现There was a problem with the editor ‘vi’

今天在Mac OS X 10.9.3上使用git的时候遇到这么一个问题,执行git commit操作会显示如下错误:
There was a problem with the editor ‘vi’

搜寻了一下相关的解决方案,发现好多人遇到了这个问题。似乎是因为vim的返回值有问题导致的。
所以执行一下下面这条命令:
$ git config –global core.editor /usr/bin/vim
将git使用的编辑器强制指定一下,就可以正常使用了。具体的错误分析就不翻译了,贴在下面:

I have had an annoying problem with git and vi. I like to use vim to edit my commit messages, but I’ve been hit with this annoying message every time I write the message and quit vim.

error: There was a problem with the editor ‘vi’
After a little bit of digging I found that this message is shown by git when the editor exits with a non-zero exit code. You can use $? to see the exit code of last script or application.

$ vim # then exit vim with :q immediately
$ echo $?
1
I’m still not sure why vim is exiting with non-zero exit code, but it is definitely related to my .vimrc – moving it to .vimrc.bak seemed to fix the problem. I’m using the excellent pathogen plugin to manage my vimfiles, so I plan to go through that and my installed plugins to find the cause of the problem.

There is a fix though, I’m not sure what’s causing this, but I found a post on the vim-mac mailing list which shows this:

$ vim # and exit with :q
$ echo $?
1
$ /usr/bin/vim # and exit with :q
$ echo $?
0
$ which vim
/usr/bin/vim
Running vim with /usr/bin/vim seems to make it exit cleanly. So to fix the problem with git commit you just need to run this:

$ git config –global core.editor /usr/bin/vim
I’d still like to get to the root of the problem, but this gets me my git commit messages back!