惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

Kenneth Friedman

Alan Kay Answers MIT Scheme on Apple Silicon (M1 Mac) Introducing, Toski Marginal Notes MIT: Second Year Masters Oh The Places I've Been Introducing, Scribr The 2034 Website Real and Spectacular
Open With Sublime
Kenneth Friedman · 2018-12-26 · via Kenneth Friedman

A quick way to open any file in Sublime, on a Mac.

Sublime Text — especially on the Mac — is known to be a super simple, easy text editor. It loads fast, and it's fairly minimal. Whenever I want to quickly open a text file or a small program Sublime is my go to choice.

The Problem

To quickly inspect files with Sublime Text, I need to be able to open any given file in Sublime from the Mac Finder.

Finder does have the notion of a "Default Application", but there are two problems. First, it works at a per file-extension level. You can assign a particular file type to open with a default application, but you can't assign all files to have one default application. Second, there can be only be one default application, which is problematic when you have a files that need multiple apps. For example, with an HTML file, it is best to open with a text editor to modify the file, but it's best to open in a browser to actually view the file.Why do websites need a separate editor and viewer? Don't get me started. Why isn't the authoring always on?

A Flaw in the Obvious Solution

Finder's "Open With" menu.

Luckily, Finder has a context menu (right clicking on a file), that includes an "Open With..." submenu. This menu lists some of the possible applications that can open the given file type. At first, I tried adding a keyboard shortcut to this Finder menu option. Adding keyboard shortcuts is very easy on the Mac... you can provide the exact name of the menu item, and then attach a key command to it. Because the default application uses "Cmd+O", it makes sense that the secondary application should be "Shift+Cmd+O."

Finder trying to find applications that can open this file.

Unfortunately, the list of possible "Open With..." items is generated on the fly, when the user clicks or hovers on the menu item. You can see this very briefly, when the list is empty and the menu says "Fetching..." When the standard keyboard shortcut is invoked, it looks for the exact menu item "Open With...Sublime", but since the list isn't populated, it can't find it, and the shortcut doesn't run.

The Real Solution

The secret lies with Services. Services is another great Mac feature that allows you script applications. I created a Service using Automator. The Service is always available, preloaded, in the Finder menu. (Under Finder->Services).

The Service (now called Workflow in Automator) is very simple. As shown below, it simply takes the currently selected files or folders in Finder, and opens them in Sublime. Easy!

Then, the Service can be "installed" by saving the file to ~/Library/Services/

Finally, the installation makes it available in Finder's Service menu. Therefore it is easy — once again — to attach a keyboard shortcut to the Service, which opens the currently selected file or folder in Sublime.

Now — using this Automator Service and Keyboard Shortcut combination — I can open any text file in Sublime with a simple Shift+Command+O keyboard shortcut.