1

What is wrong with this piece of Apple Script, It gives the error:

Syntax Error Expected end of line, etc. but found application constant or consideration.

repeat while true
    set t to (time of (current date))
    if (t > 30000) and (t < 30600) then
        tell application "Safari"
            activate
            delay 1
            tell application "System Events" to keystroke "1" using command down
            delay 1
            tell application "System Events" to key code 48 using {option,control,shift} down
            repeat 100 times
                tell application "System Events" to key code 48 using shift down
                delay 0.5
            end repeat
            tell application "System Events" to key code 48
            delay 1
            tell application "System Events" to key code 48
            delay 1
            tell application "System Events" to keystroke "String"
            delay 1
            tell application "System Events" to key code 36
        end tell
    end if
    delay 300
end repeat

1 Answer 1

3

using {option,control,shift} down doesn't work; use using {option down, control down, shift down} instead.

BTW, I should probably describe how I found this problem, since it's a very general and useful troubleshooting technique. I don't know AppleScript syntax well enough to spot this as a problem, but I do know how to isolate a problem: by removing parts of the code (or replacing them with placeholders if necessary), and seeing if the problem goes away. By seeing which bits of code remove the problem, I can isolate where the specific problem is.

This technique is the basis of the "divide and conquer" method described here for creating a minimal, reproducible example of a problem before posting it here. This is an extremely useful process to go through before posting, both because it'll reduce the amount of irrelevant stuff people here have to look through to find the problem, and also because there's a good chance you'll spot the problem yourself once it's isolated out.

In this case, I used the opposite technique: rather than trying to remove everything except the problem, I tried to remove only the problem. That is, I removed sections of code, and if the problem remained I put that section back and tried removing something else instead. But if removing a section did remove the problem, I'd put it back and then try removing just a smaller piece of it.

So, the first thing I did was remove most of the contents of the tell application "Safari" ... end tell section (leaving just activate, so it wouldn't complain about an empty section), hit the Compile button, and got no error. So I put it back (Command-Z to undo), and removed just the repeat 100 times ... end repeat section. Compile, still get the error. Ok, put that back... and there's one other line that looks different from most of the others. So I removed the line with {option,control,shift}, Compiled, error gone!

So at that point I knew where the error was coming from, and it was just a matter of trying variations on the syntax until I found one that worked.

1
  • Might be quicker to take a look at the application’s scripting dictionary to see the terms it uses - some are harder to guess than others.
    – red_menace
    Commented Mar 23, 2021 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .