0

Purely as an experiment, I’m trying to do something rather complex with AppleScript, mostly as an academic exercise more than anything, but I’m running into trouble. Here’s what’s happening.

First, I have a code library, called “ascr_code_library.scpt”, containing just one method:

on return_string_position(this_item, this_str, delim)
    set old_delims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to delim
    set this_list to text items of this_str
    set found_pos to 0
    repeat with i from 1 to the count of this_list
            if item i of this_list is equal to this_item then set found_pos to i
    end repeat
    set AppleScript's text item delimiters to old_delims
    return found_pos
end return_string_position

Then, I have this script, “test-2.scpt.” What it does is very simple, and pretty self-explanatory:

set scr_lib to load script (choose file with prompt "Please pick a library")

tell scr_lib
    return_string_position("Who", "Who am I?", " ")
end tell

But what I get when I run the script and choose the file is the following error:

*“«data scpt4D617259332E303000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 . . . . . . . (etcetera, goes on fou five pages) . . . 1000101010CFADEDEAD» doesn’t understand the return_string_position message.”*

So where am I going wrong? It’s loading the script correctly, so far as I can tell. But where else could I be going wrong in such a simple script? I tried prefixing the method call with “my,” but that didn’t work either. Any ideas?

1
  • Your code works fine for me with no errors. There must be something else that your not telling us about... because the code you're showing works. Sep 5, 2012 at 21:16

1 Answer 1

0

As mentioned in your previous question, I like this script better because it avoids delimiters and returns each instance.

on return_string_position(this_item, this_str)
    set theWords to every word of this_str
    set matchedWords to {}
    repeat with i from 1 to count of theWords
        set aWord to item i of theWords
        if item i of theWords = this_item then set end of matchedWords to i
    end repeat
    return matchedWords
end return_string_position

return_string_position("very", "The coffee was very very very very very ... very hot.")

You can call the script like this:

run script file ((path to desktop as text) & "test 1.scpt") with parameters {"very", "The coffee was very very very very very ... very hot."}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.