Last active
November 18, 2019 05:58
-
-
Save ods94065/7ac6ee01e1d816d3948365c925219714 to your computer and use it in GitHub Desktop.
Lilypond integration with TextWrangler via AppleScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Author: Henk van Voorthuijsen | |
-- From lilypond-devel, 21 Jul 2008, "Re: MacOS 10.5 Applescript for TextWrangler" | |
-- https://lists.defectivebydesign.org/archive/html/lilypond-devel/2008-07/msg00288.html | |
set lilypondPath to convertPath(path to application "LilyPond" as text, 2, -2, "/") | |
tell application "TextWrangler.app" | |
save first document | |
set documentName to name of first document | |
set filePath to file of first document as text | |
end tell | |
tell me to set basename to base(filePath) | |
set documentPath to convertPath(filePath, 2, -2, "/") | |
set lpScript to "PATH=$PATH:" & quoted form of (lilypondPath & "Contents/Resources/bin") & ":. | |
cd " & quoted form of substring(documentPath, 1, -2) & " | |
lilypond " & quoted form of documentName | |
tell application "Terminal" | |
set currentTab to do script (lpScript) in first window | |
repeat while busy of currentTab | |
end repeat | |
end tell | |
tell application "Finder" to open basename & ".pdf" | |
on base(filename) | |
set delim to text item delimiters | |
set text item delimiters to "." | |
set basename to first text item of filename | |
set text item delimiters to delim | |
return basename | |
end base | |
on convertPath(path, firstItem, lastItem, prefix) | |
set delim to text item delimiters | |
set text item delimiters to ":" | |
set pathItems to text items of path | |
set text item delimiters to delim | |
set uPath to prefix | |
repeat with pathItem in items firstItem thru lastItem of pathItems | |
set uPath to uPath & pathItem & "/" | |
end repeat | |
return uPath | |
end convertPath | |
on substring(theText, firstPos, lastPos) | |
set delim to text item delimiters | |
set text item delimiters to "" | |
set retVal to (characters 1 thru -2 of theText) as text | |
set text item delimiters to delim | |
return retVal | |
end substring |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment