Created
April 15, 2011 04:41
-
-
Save zeuxisoo/921152 to your computer and use it in GitHub Desktop.
Append header on top of document
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
# Neo.Lo | |
# 2011-04-15 12:38:10 PM | |
tell application "TextWrangler" | |
set author to "Neo.Lo" | |
set website to "http://studio.zeuik.com/" | |
set wrap to 80 | |
set out to {} | |
set end of out to " * Name : " & name of document 1 | |
set end of out to " * Author : " & author | |
set end of out to " * Contact : " & website | |
set end of out to " * Modified: " & (do shell script "date|sed 's/ / /g'") | |
-- find the max string length | |
set maxLen to 0 | |
-- find the largest string | |
repeat with p in out | |
set len to length of p | |
if len > maxLen then set maxLen to len | |
end repeat | |
-- pad each item in list | |
#set cnt to count (out) | |
#repeat with i from 1 to cnt | |
# set str to item i in out | |
# set strLen to length of str | |
# set pad to (wrap - strLen) - 1 | |
# set pSpaces to "" | |
# repeat with j from 1 to pad | |
# set pSpaces to pSpaces & space | |
# end repeat | |
# set pSpaces to pSpaces & "*" | |
# set item i in out to str & pSpaces | |
#end repeat | |
-- create comment start | |
set the beginning of out to "/*" | |
#repeat with i from 2 to wrap | |
# set item 1 of out to item 1 of out & "*" | |
#end repeat | |
--create comment end | |
#set the end of out to "" | |
#repeat with i from 2 to wrap | |
# set item -1 of out to item -1 of out & "*" | |
#end repeat | |
set item -1 of out to item -1 of out & return & " */" | |
-- fold the list and write to application | |
set OD to AppleScript's text item delimiters | |
set _ND to return | |
set AppleScript's text item delimiters to _ND | |
set text of selection to ((out as string) & return) | |
set AppleScript's text item delimiters to OD | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment