Permalink
Browse files

Simple script to make a symlink mirror of your markdown pages so you …

…can open up in any random editor.
  • Loading branch information...
1 parent 885df93 commit ca30c5e1360c99796b68fb82ff98ea68e187338e @ccgus committed Oct 29, 2013
Showing with 47 additions and 0 deletions.
  1. +47 −0 plugins-script/Make Markdown Symlink Mirror.jstalk
@@ -0,0 +1,47 @@
+
+function isMarkdown(uti) {
+ return uti == "public.plain-text" || uti == "net.daringfireball.markdown";
+}
+
+function documentPathForUUIDInDocument(itemUUID, document) {
+
+ var pageFolder = [itemUUID substringWithRange:NSMakeRange(0, 1)];
+ var docFolder = [[document fileURL] path];
+ var fullPath = docFolder + "/pages/" + pageFolder + "/" + itemUUID;
+
+ return fullPath;
+}
+
+function main(windowController, document) {
+
+ var ws = [NSWorkspace sharedWorkspace];
+ var fm = [NSFileManager defaultManager];
+
+ var mirrorFolder = @"/tmp/foo/"
+
+ [fm createDirectoryAtPath:mirrorFolder withIntermediateDirectories:true attributes:nil error:nil];
+
+ var uuids = [document pageUUIDs];
+
+ for (idx = 0; idx < uuids.length(); idx++) {
+ var uuid = uuids[idx];
+
+ var page = [document pageForUUID:uuid];
+
+ var name = [page displayName]
+
+
+ var uti = [page uti];
+
+ if (isMarkdown(uti)) {
+ var sympath = [mirrorFolder stringByAppendingPathComponent:[name stringByAppendingPathExtension:"md"]];
+ var dataPath = documentPathForUUIDInDocument(uuid, document);
+
+
+ [fm createSymbolicLinkAtPath:sympath withDestinationPath:dataPath error:nil]
+
+ }
+ }
+
+ [ws openFile:mirrorFolder];
+}

0 comments on commit ca30c5e

Please sign in to comment.