image
image

Go Back   macosx.com > Design, Media, Programming & Scripting > Software Programming & Web Scripting

Reply
 
LinkBack Thread Tools
  #1  
Old March 18th, 2006, 02:58 PM
Registered User
 
Join Date: Jun 2003
Location: Whitehorse, Yukon
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
neuby is on a distinguished road
BBedit won't take variable input!! Ack!

Ok folks - I am going insane here! Just to make sure that the problem was not in some surrounding code (like where the BBedit tell was placed), I moved all of the BBedit stuff to its own handler, passed the variables to that handler then tried it there.


on grep_it(current_name, new_item_name)
tell application "BBEdit 6.5"
activate
if current_name = "CBB91F15-10D9-4A91-9C6D-84F29E93F44F" then
beep 2
display dialog ("The string is correct")
end if
--set current_name to "CBB91F15-10D9-4A91-9C6D-84F29E93F44F"

replace current_name using new_item_name saving yes searching in alias "Macintosh HD:Usersld_bfindlay:Sites:" options {search mode:grep, case sensitive:true, match words:false, extend selection:false, showing results:true}

end tell
end grep_it


The above code does display the dialog - indicating that this handler sees the correct string value, yet fails on the replace. (BBedit activates, cranks through the files, but fails to find or replace anything - no results window pops up.)

However, if i uncomment set current_name to "CBB91F15-10D9-4A91-9C6D-84F29E93F44F", just before passing it to the replace command, it works! Holy Crap Batman - it is THE SAME value!! Tested by the if logic. If I set it manually, it works, if I set it by passing the variable into the handler, it doesn't! (Course without accepting the variable, the entire script is useless!!)

-Brick walled on this one.
Reply With Quote
  #2  
Old March 18th, 2006, 04:35 PM
Registered User
 
Join Date: Jun 2003
Location: Whitehorse, Yukon
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
neuby is on a distinguished road
Progress?

Hmm - progress, of a sorts. I have found the part in the script that is screwing things up. Just don't understand WHY or HOW it is screwing it up.

Before I call the BBedit code, I trim the extension and the "." off of the filename that I am replacing, as per:

tell application "Finder"
set extension to name extension of this_item
set trim_count to (count of characters in extension) + 1
set current_name to (characters 1 thru ((count of characters in current_name) - trim_count) of current_name) as string --trims the extension off the filename
set the parent_container_path to (the container of this_item) as text
--set grep_target to (container of (container of (parent_container_path as alias))) as string --use two levels up from current folder as grep path
set new_item_name to new_item_name as string
end tell


If I call the BBedit code BEFORE this tell statement, it DOES work - mind you it is finding "CBB91F15-10D9-4A91-9C6D-84F29E93F44F.html" and replacing it with 'entry1". (Not the behaviour I want, but it does demonstrate that the BBEdit code appears to function)

However, If I place the call AFTER I strip the extension and dot from the filename, it fails.

the line that appears to screw things up is

set current_name to (characters 1 thru ((count of characters in current_name) - trim_count) of current_name) as string --trims the extension off the filename

Now - to my mind, this first turns current_name into a list of characters, but it then coerces it back to a string.

Recall, that I put a checking if statement in the code

if current_name = "CBB91F15-10D9-4A91-9C6D-84F29E93F44Fl" then
beep 2
display dialog ("The string is correct")
end if

just before the BBedit replace command, and Applescript does indeed see this as the correct string! However, BBedit does not.

is this a program bug in BBedit? Applescript? My brain? What?
Reply With Quote
  #3  
Old March 18th, 2006, 08:53 PM
Registered User
 
Join Date: Jun 2003
Location: Whitehorse, Yukon
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
neuby is on a distinguished road
Solved

Feels like I am having a diologue with myself, but for the interested reader, I solved this puzzle:

Ok, that was weird!

I finally figured out that BBedit was seeing something different in the replace text, than what Applescript was displaying on the screen. I clued in that setting the current_name to characters, and then coercing it back to string was the problem. Turns out that before doing this it was class "utxt" and after it was class "TEXT". That was the problem. Coerced it back to unicode, and all went well.

Dang - that was subtle, and to me still appears to be a fault in BBedit - it states that it wants a string input in the BBedit dictionary.

Oh well, on to the next stage...
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
InDesign. Variable info... possible?? wicky Design & Media 19 March 6th, 2006 12:15 PM
set $PATH environment variable? tr333 Unix & X11 7 October 4th, 2005 12:11 AM
path variable shadowfax Unix & X11 3 July 28th, 2003 01:15 PM
Terminal User Input into a variable for a script cabbage Unix & X11 5 December 6th, 2002 06:51 PM
TERM_PROGRAM: Undefined variable. holmBrew Unix & X11 9 September 23rd, 2002 08:17 AM


All times are GMT -5. The time now is 05:43 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC1
Copyright 2000-2010 DigitalCrowd, Inc.