AppleScript Script is doing nothing

Discussion in 'Mac Programming' started by shadow-rising, Sep 1, 2008.

  1. macrumors newbie

    Ok so I'm working on an applescript just for fun. I'll be using it on a network where i can change the text file from another computer. What it is supposed to do is if the text in the file changes then it speaks the 1st line using the voice named on the 2nd line, pausing the length of time on the 3rd line and so on down the text file until it reaches the end. at this point just ignore the backup app unless that's causing the problem it's has to do with in case someone exits the app the backup up will open it back up and if someone exits the backup app it opens this app back up but I commented that part out just to make sure it wasn't causing the problem. The script is pretty self explainitory So here it is.

    --initialize variables
    set i to 1
    set SpeechList to {}
    set VoiceList to {}
    set PauseList to {}
    set AppleScript's text item delimiters to ";" & (ASCII character 13)
    open for access file "Macintosh HD:users:shared:backup:data.txt"
    set previous_text to "null"

    --starting repeat that is the basis of the entire application
    set raw_text to read file "Macintosh HD:users:shared:backup:data.txt"
    set text_list to text items of raw_text
    --testing to see if backup app is open
    --tell application "backup"
    --if it is running then
    --open backup app if it isn't open
    --tell application "Finder"

    --open document file ""

    --end tell
    --end if
    --end tell
    if raw_text = previous_text then

    -- seperate each item into a list
    set text_list to text items of raw_text

    -- divide up the list: we want a list of the spoken terms, one of the voice to use, and last one of the pause between the spoken lines
    set i to 1
    set n to the number of items in text_list
    repeat while i < n
    set SpeechList to SpeechList & item i of text_list
    set VoiceList to VoiceList & item (i + 1) of text_list
    set PauseList to PauseList & item (i + 2) of text_list
    -- return AppList
    set i to (i + 3)
    end repeat
    --speak the lists: this is the whole reason this script was wrote
    set i to 1
    set n to (the (number of items in SpeechList) + 1)
    repeat while i < n
    say item i of SpeechList using item i of VoiceList
    delay item i of PauseList
    set i to (i + 1)
    end repeat
    set previous_text to raw_text
    end if

    end repeat

Share This Page