在Mac中用快捷键快速插入日期时间

在Windows中有AutoHotkey这个好东东帮我快速插入日期时间,输入[mm然后敲空格就可以了。在Mac中就没有这么好的事了,虽然能够实现,但是没有AutoHotkey方便。还是要借助于AppleScript,但是并不能适用于Mac中任何文本输入的地方,比如DayOne的弹出窗口就不能用,另外还有一个限制:只能对选中的文字进行操作。

我使用的是这个文章里面的方案:

http://www.sixhat.net/applescript-insert-date-and-time-into-your-documents.html

代码是:

-- Insert Date and Time into your documents
-- @2012 David Rodrigues
set date_ to ((current date) as string)
set the clipboard to the date_
tell application "System Events"
    set frontmostApplication to name of the first process whose frontmost is true
end tell
tell application frontmostApplication
    activate
    tell application "System Events"
        keystroke "v" using {command down}
    end tell
end tell

注意它会改变粘贴板的内容。我为它定义了一个快捷键:Cmd+Alt+Shift+F。使用之前,可以先敲一个字母,然后选中字母,按这个快捷键,就会显示出来日期时间了。比如现在的时间是:  2014-12-22 19:39:03 +0800。

下面的英文描述是下面参考第一个链接文章的内容,有时间再翻译。

Below is a very simple AppleScript that inserts the date, time and timezone in the format that Jekyll requires.

do shell script "date +%Y-%m-%d\\ %H:%M:%S\\ %z"

To make inserting it simple, it’s possible to assign a keyboard shortcut, by turning it into a Service in Automator.

  1. Open Automator.app
  2. Create a new Service
  3. Set it to receive selected text in any application
  4. Check the ‘Output replaces selected text’ tick-box
  5. Insert the ‘Run AppleScript’ action
  6. Copy and paste the above AppleScript
  7. Press run to make sure it works
  8. Save the .workflow file to ~/Library/Services
  9. Open the Keyboard > Keyboard Shortcuts system preference pane, select Services in the left column, then find the Service you just created.
  10. Assign a keyboard shortcut. I use Command + Option + d

There is one pitfall: it only works on selected text.

When saving a post for Jekyll, the file-name also requires a date—but not a time. For this, you can follow the same process as above with a modified AppleScript:

do shell script "date +%Y-%m-%d"

For this, I use the keyboard shortcut Command + Option + Shift + d.

I would love it if the Service created the entire file name. So if the post title ‘This is a Post Title’ was on the clipboard, it would create a file called 2012-11-10-this-is-a-post-title.md; replacing spaces with hyphens and converting it to lowercase. However, that’s well beyond my very limited AppleScript knowledge.

参考:

http://andytaylor.me/2012/11/10/creating-an-osx-service-to-insert-the-current-date-and-time/

http://www.question-defense.com/2013/01/28/title-osx-keyboard-shortcut-for-insert-date-and-time-insert-datetime-in-textmate

时间: 2024-08-03 15:02:39

在Mac中用快捷键快速插入日期时间的相关文章

Sublime Text 3 插入日期时间等

Sublime  Text 并没有自带插入日期时间的功能,但是可以通过插件的方式实现,这也是sublime可扩展性的强大体现.详细的步骤如下: 1. 菜单栏:Tools -> New Plugin... 2. 此时会打开一个插件模版文件,使用下面的内容覆盖 import datetime, getpass import sublime, sublime_plugin class AddDateTimeStampCommand(sublime_plugin.TextCommand):     de

[数据库基础]——快速浏览日期时间转换

数据库日期和时间类型 相互转换     time ? date     time ? smalldatetime     time ? datetime     time ? datetime2     time ? datetimeoffset     date ? smalldatetime     date ? datetime     date ? datetime2     date ? datetimeoffset     smalldatetime ? datetime     s

SQL 插入日期时间 变量值

--看看吧^^ CREATE TABLE #temp ( test datetime ) go --SQL: INSERT #temp SELECT 1.1 UNION ALL SELECT 1 GO --SQL: INSERT #temp SELECT '2011-1-1' UNION ALL SELECT GETDATE() GO SELECT * FROM #temp /* 1900-01-02 02:24:00.000 1900-01-02 00:00:00.000 2011-01-01

在JavaScript文件中用jQuery方法实现日期时间选择功能

JavaScript Document $(document).ready(function(e) { 在文本框里面显示当前日期 var date = new Date(); var nian = date.getFullYear(); var yue = date.getMonth()+1; var tian = date.getDate(); $("#rq").val(nian+"-"+yue+"-"+tian); 给文本框加点击事件 $(&

sqlite3插入日期时间出错解决

正确写法 insert into hhf_records(RegistrationNumber,MachinesNumber,InDataTime,Flag,CType) values (11,1,datetime('2014-10-15 07:50:34'),0,0);select LAST_INSERT_ROWID() 错误写法 insert into hhf_records(RegistrationNumber,MachinesNumber,InDataTime,Flag,CType) v

Sublime Text自定义插入当前时间的插件

很奇怪为什么强大的Sublime编辑器为什么没有添加当前时间的快捷键,不过还好Sublime可以通过自定义插件的方式来实现任何你想要的效果 1. 创建插件: Tools → New Plugin: 新建文件并 保存为Sublime Text 2\Packages\User\addInfo.py importdatetime importsublime_plugin classAddInfoCommand(sublime_plugin.TextCommand): defrun(self,edit)

在excel中如何快速插入当前日期和时间

使用快捷键,输入的日期和时间不会自动刷新. 1.插入当前日期: Ctrl+分号.即同时按住键盘上的Ctrl键和分号键. 输出格式:2014/11/4 2.插入当前时间:Ctrl+Shift+分号.即同时按住键盘上的Ctrl.Shift和分号键. 输出格式:19:05 3.插入当前日期和时间:在同一个单元格中先使用快捷键插入当前日期,然后打个空格,再插入当前时间.

(转)java向MySQL插入当前时间的四种方式和java时间日期格式化的几种方法(案例说明)

java向MySQL插入当前时间的四种方式和java时间日期格式化的几种方法(案例说明);部分资料参考网络资源 1. java向MySQL插入当前时间的四种方式 第一种:将java.util.Date类型的时间转成mysql数据库识别的java.sql.Date类型时间 注:java.util.Date是java.sql.Date的父类 Date time= new java.sql.Date(newjava.util.Date().getTime()); 第二种: java用PreparedS

java向MySQL插入当前时间的四种方式和java时间日期格式化的几种方法(案例说明)

java向MySQL插入当前时间的四种方式和java时间日期格式化的几种方法(案例说明);部分资料参考网络资源 1. java向MySQL插入当前时间的四种方式 第一种:将java.util.Date类型的时间转成mysql数据库识别的java.sql.Date类型时间 注:java.util.Date是java.sql.Date的父类 Date time= new java.sql.Date(newjava.util.Date().getTime()); 第二种: java用PreparedS