Re: Working Directory in Worksheet Script

2013-04-19 Thread John Delacour
On 19/4/13 at 18:51, listmeis...@suddenlink.net (Christopher 
Stone) wrote:


I got tired of typing 'pwd' 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 bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at

If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.

Follow @bbedit on Twitter: 

--- 
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 bbedit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Working Directory in Worksheet Script

2013-04-19 Thread Christopher Stone
Hey Folks,

I got tired of typing 'pwd' 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 bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at

If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 

--- 
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 bbedit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Sequential numbering

2013-04-19 Thread hoyu yiu
Hi Chris

This script works great with BBedit.
Thank you for providing such a useful script.
However, is there a way to edit this script so it can also work with 
TextMate?

Thanks

Must appreciated.


-Hoyu

On Tuesday, September 4, 2012 3:48:35 AM UTC-4, Christopher Stone wrote:
>
> On Sep 03, 2012, at 01:42, AB > wrote:
>
> Can anyone help with a script or text filter to add a number after a 
> string in a file
>
> __
>
> Hey AB,
>
> Kendall's Perl script is far superior for speed with nearly instant 
> replacement of sample text with 450 replacements.
>
> Nevertheless it can be done pretty easily with Applescript:
>
> -
> set regexStr to "\\b(the)\\b"
> set _cntr to 0
> tell *application* "BBEdit"
> tell front *text window*'s *text*
> *select* *insertion point* before *character* 1
> repeat
> set fndRec to *find* regexStr options {search mode:grep, case sensitive:
> false}
> if (found of fndRec) = true then
> set _cntr to _cntr + 1
> tell (a reference to found object of fndRec)
> set its *text* to (get its *text* as *text*) & _cntr
> end tell
> else
> exit repeat
> end if
> end repeat
> *select* *insertion point* after *character* -1
> end tell
> end tell
> -
>
> This script however takes about 4 seconds to complete on the same example 
> text when run from BBEdit's script menu.
>
> --
> Best Regards,
> Chris
>
>

-- 
-- 
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 bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at

If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 

--- 
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 bbedit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.