在Windows中有AutoHotkey這個好東東幫我快速插入日期時間,輸入[mm而後敲空格就能夠了。在Mac中就沒有這麼好的事了,雖然可以實現,可是沒有AutoHotkey方便。仍是要藉助於AppleScript,可是並不能適用於Mac中任何文本輸入的地方,好比DayOne的彈出窗口就不能用,另外還有一個限制:只能對選中的文字進行操做。
html
我使用的是這個文章裏面的方案:shell
http://www.sixhat.net/applescript-insert-date-and-time-into-your-documents.html
app
代碼是:post
-- 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。
ui
下面的英文描述是下面參考第一個連接文章的內容,有時間再翻譯。this
Below is a very simple AppleScript that inserts the date, time and timezone in the format that Jekyll requires.spa
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..net
Open Automator.app翻譯
Create a new Servicecode
Set it to receive selected text in any application
Check the ‘Output replaces selected text’ tick-box
Insert the ‘Run AppleScript’ action
Copy and paste the above AppleScript
Press run to make sure it works
Save the .workflow
file to ~/Library/Services
Open the Keyboard > Keyboard Shortcuts
system preference pane, select Services in the left column, then find the Service you just created.
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/