Hey all,
Here's a small script to convert file paths to
TiddlyWiki links.
It has been requested (sort of)
on the TiddlyWiki mailing list.
The script is meant to be called via the SendTo context menu, but it can also be run manually with parameters; the first parameter is the file path, the second parameter is an optional link title.
The code has not been extensively tested, and you will have to
manually create the SendTo shortcut (also see
MSKB) - but it should do the job.
Also, be aware that this will overwrite the clipboard contents! (I couldn't be bothered coming up with a satisfying solution for that... )
I've uploaded the
source code as well as the
compiled EXE.
Here's the source code again:
Code:
/*
TiddlyWikifier v1.0
by FND
Converts Windows file paths to TiddlyWiki PrettyLinks
*/
/*
ToDo:
- backup clipboard
- automatically add a shortcut to the SendTo menu
*/
/*
Changelog
¯¯¯¯¯¯¯¯¯
# v1.0 (2007-06-08)
* initial release
*/
/*
********** Settings, Variable Declarations **********
*/
#SingleInstance Force
#NoEnv
OnExit, quit
programName = TiddlyWikifier
programVersion = 1.0
programFullName = %programName% v%programVersion%
programAuthor = FND
filePath =
title =
/*
********** Auto-Execute Section **********
*/
; backup clipboard contents
;clipboardBak := ClipboardAll ; DEBUG: disabled, as it complicates script termination
; process command line parameters
GoSub, getParams
; get title (optional)
If(title = "")
{
InputBox, title, %programFullName%, Please enter a title for your link.`n(Press cancel to not use a custom title.)
,,,,,,,, %filePath%
If(ErrorLevel = 1)
title =
}
; convert file path
StringReplace, filePath, filePath, \, /, All ; convert slashes to Unix format
filePath = file:///%filePath% ; add file protocol
; construct PrettyLink
If(title = "")
tiddlyLink = [[%filePath%]]
Else
tiddlyLink = [[%title%|%filePath%]]
; copy PrettyLink to clipboard
Clipboard := tiddlyLink
; end of auto-execute section
Return
/*
********** Subroutines **********
*/
; process command line parameters
getParams:
If 0 > 0
{
filePath = %1%
if(title != "")
title = %2%
}
Return
; terminate script
quit:
; restore clipboard contents
;Clipboard := clipboardBak ; DEBUG: disabled; see above
; terminate script
ExitApp
Return
_________________
Improving my world, one script at a time.
Join the AutoHotkey IRC channel:
irc.freenode.net #autohotkey