Hey Folks,
I got tired of typing 'pwd'<enter><Cmd-Z> to check the working directory of a
worksheet, so I wrote a script to add/update it as a comment on line one. It
attempts to restore the cursor location or selection.
Presently I have it bound to Cmd-Opt-Ctrl-P.
--
Best Regards,
Chris
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2013-04-19 : 05:28
# dMod: 2013-04-19 : 05:47
# Appl: BBEdit
# Task: Print Working Directory (PWD) as a comment in the first line of a
BBEdit worksheet.
# Tags: @Applescript, @BBEdit, @PWD, @Worksheet
-------------------------------------------------------------------------------------------
try
tell application "BBEdit"
if class of front document is shell document then
tell front shell window
set _sel to selection
set selSt to characterOffset of _sel
set selLen to length of _sel
set oldTextLen to number of characters
set _pwd to working directory of its active document
set _pwd to "# $PWD == " & _pwd
if (contents of line 1) ≠ _pwd or (contents of line 1) = "" then
if (contents of line 1) starts with "# $PWD == " then
set (contents of line 1) to _pwd
else if (contents of line 1) = "" then
set (contents of line 1) to _pwd & linefeed & (contents of line 1)
else
set (contents of line 1) to _pwd & linefeed & (contents of line 1)
end if
set newTextLen to number of characters
if newTextLen ≠ oldTextLen then
set selSt to selSt + (newTextLen - oldTextLen)
end if
if selLen = 0 then
select insertion point after character (selSt - 1)
else
select (characters selSt thru (selSt + selLen - 1))
end if
end if
end tell
end if
end tell
on error e number n
set e to e & return & return & "Num: " & n
tell me to set dDlg to display dialog e with title "ERROR!" buttons
{"Cancel", "Copy", "OK"} default button "OK"
if button returned of dDlg = "Copy" then set the clipboard to e
end try
-------------------------------------------------------------------------------------------
--
--
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem,
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.