A short story first: I had a major crash on my Mac about a year and two months ago when I had to secure all my stuff over to another harddrive. Since then I’ve managed to get my Mac working again but I haven’t been using those scripts that I made before the crash so when I opened up one of them today to make some changes to it so that I could use it I noticed that some parts of the code had been changed. I guess that the changes has been made when the scripts where compiled. Though I can change some things others doesn’t work at all - like keystrokes with command down.
This is what a part of my code looked like when I reopened it:
tell application "Safari"
activate
tell application "System Events"
try
tell application "Safari" to do JavaScript "document.location.href = '" & (login_url) & "'" in document 1
delay 8
«event prcskprs» (ASCII character 9)
«event prcskprs» (ASCII character 9)
delay 1
«event prcskprs» (ASCII character 13)
delay 3
«event prcskprs» "w" given «class with»:command down
end try
end tell
end tell
By changing the first three «event prcskprs» to keystroke I can still get those “functions” to work but if I try to do the same thing with the window-closing thing and replacing that line of code with “keystroke “w” with command down”(which as far as I can remember is the correct way to write it…knock on wood) I just get an error when I try to check it:
Model: PM7600 w. G3/500, 768mb ram, OSX.2.8
AppleScript: 1.9.1
Browser: Safari 85.8.1
Operating System: Mac OS X (10.2.x)
tell application "Safari"
activate
tell application "System Events"
try
tell application "Safari" to do JavaScript "document.location.href = '" & (login_url) & "'" in document 1
delay 8
keystroke (ASCII character 9)
keystroke (ASCII character 9)
delay 1
keystroke (ASCII character 13)
delay 3
keystroke "w" using command down
end try
end tell
end tell
My guess is that when you last tried this, Mymac4ever, you were using the GUI public beta (introduced in Mac OS 10.2 Jaguar). At the conclusion of those tests, Apple changed a few things - including the parameters of the keystroke command (‘with’ was changed to ‘using’). While your details suggest that you’re still on 10.2.x, you’re now clearly using a more recent version of System Events/UI Scripting.
You might also like to know that, had you commented out any statement(s) that wouldn’t compile, the «event prcskprs» raw codes should have still compiled automatically to ‘keystroke’. (Might save you some typing in the future.)
One other small point: since using ‘ASCII character’ involves a conversion, it’s usually faster to use AppleScript constants for characters like tab (ASCII character 9) and return (ASCII character 13). It used to be the case that ‘tab’ compiled incorrectly in a System Events tell block, although it works well in more recent versions. You may want to check that on your machine.
Good to hear that you’re getting back into some AppleScript. Welcome back!
Thanks for the tips but I still get an error when I try using instead of with. The error I get is this one (with using marked):
Since its been a while since I did all this I regret to say that I’ve actually forgot a lot about this. I’ve enabled Access for assistive devises. Are there any more settings I should remember to fix?
And yes my OS-version is 10.2.8
Model: PM7600 w. G3/500, 768mb ram, OSX.2.8
AppleScript: 1.9.1
Browser: Safari 85.8.1
Operating System: Other
In 10.2.8, unless you still have the GUI public beta software installed, you won’t be able to access these features.
Check your System Events AS dictionary. If commands like keystroke are not present in the Processes Suite, then it might be time to consider an upgrade. UI scripting was officially introduced in Mac OS 10.3, after which I’m afraid the beta software was withdrawn.
Well I guess upgrading to Panther would be a good idea but since I’m aiming towards a fresh G5 within the nearest months I don’t want another cost right now. Luckily for me though I already had the UI Scripting Beta-package downloaded so I’ve just reinstalled it. Hopefully it works the way it should.
Glad to hear that you still have the Beta package, Mymac4ever. I’m sure it will work fine for you - and it should keep you going for as long as you need, until you’re ready to upgrade. (I was quite happy to use it myself for a long time in OS 10.2.8 - way after many others had upgraded several times!)
I suppose that boxed version of Panther was auctioned off on eBay, huh?
I bet it was refreshing to go right from 10.2.8 to 10.4. (Well except for the scripts that broke and some of the bugs, but other than that how was the play Mrs. Lincoln?)
Historical aside for the non-Americans: “other than that, how was the play Mrs. Lincoln?” refers to Abraham Lincoln (the 16th president of the United States) being assasinated while attending a play. Later, it was the punchline to a tasteless joke which has now become a sort of sarcastic remark for people who manage to find one small good thing amongst a whole bunch of bad things…
I am so obsessive about OS releases – I have run every one from 6.0.8 onward… I know that probably makes me weird, but I have always found the operating system the most fascinating part of a Mac.
And if you don’t think that’s weird or obsessive enough – I have eight different books on AppleScript. Not that any of this makes me any kind of expert. I still rely on help from a certain AppleScript guru – although a lot less then I used to.
Hi, Tom! Yeah - might have got a good price for it there, too - considering how it must have already achieved antique status…
Quite a leap. The new “bells and whistles” are a lot of fun - and i think there are more fixes than breakages (the latter of which I seem to have an uncanny knack of stumbling upon). :lol:
You come across as pretty knowledgeable to me, Tom - and I’ve no doubt that he’s been well impressed with your progress!
On the contrary, I particularly appreciated the American history lesson. Good to learn how phrases like that originated!