On 19/4/13 at 18:51, [email protected] (Christopher
Stone) wrote:
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.
Hello Chris,
I just felt like a bit of useless amusement this evening, so
here's my variant of your script:
tell application "BBEdit"
if class of front document is shell document then
tell front shell window
activate
set {_key, _pwd} to {"# PWD: ", its document's working directory}
set _selected_text to the selection
set _insertion_point to characterOffset of _selected_text
set _text_is_selected to false
if the length of the _selected_text is not 0 then
set _text_is_selected to true
set _first_char to characterOffset of _selected_text
set _last_char to _first_char + (length of
_selected_text) - 1
end if
set _current_top_line to the contents of the first line
set _new_top_line to _key & _pwd
if _current_top_line is "" or _current_top_line starts
with _key then
set the contents of the first line to _new_top_line
else
set the contents of the first line to _new_top_line &
linefeed & _current_top_line
end if
set _increment to (length of _new_top_line) - (length of
_current_top_line)
if _text_is_selected then
set _first_char to _first_char + _increment
set _last_char to _last_char + _increment
select (characters _first_char through _last_char)
else
select insertion point before character
(_insertion_point + _increment)
end if
end tell
end if
end tell
--JD
--
--
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.