Assign a shortcut for creating and opening a dated text file on OS X

1

I used to use tomboy wiki and they allowed you to bind opening a new note to a keyboard combination.

I use emacs on Lion and I want replicate this behaviour. I want to visit a new/existing file in my projects folder named yyyymmdd.md by pressing shift-z-command anywhere.

It might be possible to use automator to run a shell script that gets the iso date and then appends the directory path and .md at the end. Then it calls emacs with those arguments. As a service I can assign it to a keyboard combination. But I have no idea how to complete the steps exactly.

Fire

Posted 2011-10-14T02:23:05.583

Reputation: 123

I updated the question. – Fire – 2011-10-16T02:10:00.343

Answers

0

#!/bin/bash

date=$(date '+%Y%m%d')
f="$HOME/Desktop/$date.md"
[[ ! -f "$f" ]] && echo $'## $date\n' > "$f"
# emacs "$f"
open "$f" -a Aquamacs

And Assign a shortcut to running a script in OS X - Super User

Lri

Posted 2011-10-14T02:23:05.583

Reputation: 34 501

I believe emacs just visits the file. If it doesn't exist it is created. – Fire – 2011-10-14T20:17:03.390

If you want to open an emacs app you can just use record using applescript, then run it with osascript -e. – Fire – 2011-10-15T01:44:36.503

@Fire Only a few apps (like Finder and BBEdit) support recording AppleScripts. open -a SomeApp is pretty much equivalent to osascript -e $'tell app "SomeApp"\nreopen\nactivate\nend tell'. osascript is a lot slower though. – Lri – 2011-10-15T03:03:58.770

I'm just wondering if I can use open -a Emacs with a filename? – Fire – 2011-10-15T07:25:26.297

If you mean the graphical Emacs.app, then yeah. – Lri – 2011-10-15T07:35:04.607

I couldn't get it to work. – Fire – 2011-10-15T22:40:15.873

I did; it's time to turn it into an apple script. I also have to figure out how test if a file !exist, then create file with ## YYYYMMDD\n – Fire – 2011-10-15T22:47:30.953

You removed the applescript .scpt part placed into the scripts directory to launch from fastscripts. – Fire – 2011-10-22T19:55:35.887

@Fire Huh? I just edited out the note to chmod u+x /path/to/script. And you can also use FastScripts to run shell scripts. – Lri – 2011-10-22T21:08:14.180

0

I don't know of any freeware that does this, but here are some shareware apps :

http://nulana.com/shortcuts

http://www.alfredapp.com/ - You need the paid powerpack

http://www.obdev.at/products/launchbar/index.html - Not exactly what you want, but with an action/script you can make it work.

Kassym Dorsel

Posted 2011-10-14T02:23:05.583

Reputation: 436

The system it is designed is for Mac OS X.4.11? I'm on 10.7.2. – Fire – 2011-10-14T06:27:54.120

The forums is spammed and dead. – Fire – 2011-10-14T06:28:26.740

I'm going to assume the code is abandoned. – Fire – 2011-10-14T06:29:02.870

My bad... Please check the updated post. – Kassym Dorsel – 2011-10-14T13:38:18.310