• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Script Debugger 5: Duplicate Selection Handler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script Debugger 5: Duplicate Selection Handler


  • Subject: Re: Script Debugger 5: Duplicate Selection Handler
  • From: Christopher Stone <email@hidden>
  • Date: Wed, 12 Sep 2012 11:20:39 -0500

On Sep 11, 2012, at 18:23, Shane Stanley <email@hidden> wrote:
Not in a single line, perhaps, but it can certainly be done:
______________________________________________________________________

Hey Shane,

I didn't say the job couldn't be accomplished.  :)

But line-of-selection is a whole lot neater and more versatile objects make for more capable scripts.

Your script is nice.  It's largely the same idea as what I was working on but a slightly different implementation.  Both of them error-out though if the cursor is before character 1 or after the last character - including an empty last line.  (Not too hard to case against of course.)

------------------------------------------------------------------------------------------------
#    Purpose: Line-Selection for Script Debugger
#   Modified: 2012-09-12 : 08:38
# Depencency: None - Vanilla Applescript.
------------------------------------------------------------------------------------------------
tell application "Script Debugger"
  tell document 1
    set _src to its source text
    set {x1, x2} to character range of selection
    set _range to (text 1 thru (x1 - 1) of _src) & "Á" & (text x1 thru -1 of _src)
    set AppleScript's text item delimiters to "Á"
    tell _range's text items to set _range to {x1 - (length of last paragraph of item 1), (length of last paragraph of item 1) + (length of first paragraph of item 2) + 1}
    set selection to _range
  end tell
end tell
------------------------------------------------------------------------------------------------

I decided to implement a version using the Satimage.osax, and this one will work no matter where the cursor is located provided there is something selectable on the line (even just an eol character).

I went this direction, because I'm looking at doing more complex operations down the road - and this gave me a relatively simple proof-of-concept.

Oh.  I got tired of resetting the script context while I was testing on document 2, so I allowed for context-switching in the script and have left that in for demonstration purposes.  Why I never thought to do that before is beyond me.  :)

--
Take Care,
Chris

------------------------------------------------------------------------------------------------
#    Purpose: Line-Selection for Script Debugger
#   Modified: 2012-09-12 : 10:38
# Depencency: Satimage.osax
------------------------------------------------------------------------------------------------
try
  tell application "Script Debugger"

    

    ------------------------------------------------------------------------------------------
    # Allow testing on document 2 if this script is frontmost
    # Otherwise operate on the frontmost document.
    if name of front document is "Working Script { Script Debugger }.scpt" then
      set docRef to document 2
    else
      set docRef to document 1
    end if
    ------------------------------------------------------------------------------------------

    

    tell docRef
      set _src to its source text
      set srcLen to length of _src
      set {x1, x2} to character range of selection
      if x1 > srcLen then
        set _src to _src & "Â"
      else if x1 = 1 then
        set _src to "Â" & _src
      else
        try
          tell _src to set _src to text 1 thru (x1 - 1) & "Â" & text x1 thru -1
        on error
          return
        end try
      end if
      set {m1, m2} to {matchPos, matchLen} of fndUsing("^(.*)Â(.*)", "\\1\\2", _src, false, true, false, false, false) of me
      set m1 to m1 + 1
      set selection to {m1, m2}
    end tell
  end tell

  

on error e number n
  set e to "Error: " & e & return & return & "Error Number: " & n
  beep
  tell me to set dDlg to display dialog e buttons {"Cancel", "Copy", "OK"} default button "OK"
  if button returned of dDlg = "Copy" then set the clipboard to e
end try
------------------------------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Script Debugger 5: Select Current Line (was Duplicate Selection Handler)
      • From: Christopher Stone <email@hidden>
    • Re: Script Debugger 5: Duplicate Selection Handler
      • From: Christopher Stone <email@hidden>
References: 
 >Script Debugger 5: Duplicate Selection Handler (From: Christopher Stone <email@hidden>)
 >Re: Script Debugger 5: Duplicate Selection Handler (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Use Spotlight to Archive Files
  • Next by Date: Re: Script Debugger 5: Duplicate Selection Handler
  • Previous by thread: Re: Script Debugger 5: Duplicate Selection Handler
  • Next by thread: Re: Script Debugger 5: Duplicate Selection Handler
  • Index(es):
    • Date
    • Thread