Script working in Jaguar, not Panther

Hello there

Can anyone tell me why this script, which used to work, is no longer working in panther?

tell application "System Events"
	set theProcess to every process whose frontmost is true
	tell process theProcess
		key down {command}
		keystroke "c"
		key up {command}
	end tell
end tell
set s to the clipboard as string
-- display dialog s
set postCode to (change " " into "+" in s)
set streetMapUrl to ("http://www.streetmap.co.uk/streetmap.dll?postcode2map?code=" & postCode & "&title=Street+Map+for+" & s & "&nolocal=y")
open location streetMapUrl

-- opens a streetmap.co.uk page for the selected postcode...

If I uncomment the display dialog line I get the postcode okay, but either way I’m suddenly getting:

Applescript error -1700
Can’t make some data into the specified type

    • padmavyuha

Does this work?

tell application "System Events"
	set theProcess to item 1 of (processes whose frontmost = true)
	tell process theProcess to keystroke "c" using command down
end tell
set s to (get the clipboard) as string
set postCode to (change " " into "+" in s)
open location "http://www.streetmap.co.uk/streetmap.dll?postcode2map?code=" & postCode & "&title=Street+Map+for+" & s & "&nolocal=y"

Jon

Thanks jonn8

Unfortunately, not only do I get the same error message with your code, but it also deletes the selected postcode from my text file… :wink:

My guess is that something’s happened to the ‘change’ command to make it no longer recognise the string it’s being passed as a string. But I don’t really know enough about all this to know what I’m talking about. Sigh.

  • padmavyuha

No the “change” command is not part of vanilla AppleScript, it is a command from the Satimage.osax and, as such, was not touched when AppleScript was updated in Mac OS X 10.3.

Are you running this from a variety of applications or is the selection always in the same application? How are you running the script? I don’t see how it could actually delete something unless you’ve remapped Command-C to cut instead of copy. Finally, what is a valid code that works (just for testing purposes).

Jon

Hi Jon

Yeah, I’ve been experimenting and found that ‘change’ isn’t the problem - the problem seems to be my finished streetMapUrl string isn’t being recognised as a string by the bit of AS that’s passing it to Safari. I put in a dialog display after generating streetMapUrl, and AS was happy to display that in the Finder - it’s the open location line that’s the problem.

Incidentally, I’ve also debugged the url-generating line a bit - for & s & read & postCode &:

set streetMapUrl to (“http://www.streetmap.co.uk/streetmap.dll?postcode2map?code=” & postCode & “&title=Street+Map+for+” & postCode & “&nolocal=y”)

…becaasue [why is it so hard to type because?] the title should have + in place of spaces too…

the postcode I’m workng with is CB4 1UN - and I’m launching this script from a keystroke using iKey, as I mainly use the AS when finding places whose site I’m viewing in Safari - the ‘postcode getting replaced’ experience happens with my postcode jusxt sat in a TextEdit file (in your code, not in mine…)

Of course the other problem I’ve always had with this script is that it doesn’t reliably copy selected text to the clipboard in the first place - seems to depend on what app is being copied from, phase of the moon, stuff like that…

  • padmavyuha

…oh, new info - now that I’ve changed the streetMapUrl string, I’m getting a different AS error -1703 - some data was the wrong type (in your version and my version - yours still deletes the text…)

I’m wondering if there’s an AS code to force streetMapUrl to be a string?

  • padmavyuha

You’re saying that the code actually deletes the selection in the document?

Okay, forget that - it seems to have been a function of the particular keystroke combo that I’d assigned to your version that was replacing the selected text with a tab - changing the key combo has stopped this behaviour. Arcane.

  • Padmavyuha

More new info - there’s another post on this site about the same issue - but since I don’t have a Finder Tell block to remove (which fixed it for them), it seems to me that there’s maybe a bug with ‘open location’ in 10.3.2 (as I also don’t remember this problem happening when I first installed Panther).

  • padmavyuha

This code works for me when run in Mac OS X 10.3.2 from the Script menu in Safari, TextEdit, Finder, & Script Editor:

tell application "System Events"
	set theProcess to item 1 of (processes whose frontmost = true)
	tell process theProcess to keystroke "c" using command down
	delay 1
end tell
set s to (get the clipboard) as string
set postCode to (change " " into "+" in s)
open location ("http://www.streetmap.co.uk/streetmap.dll?postcode2map?code=" & postCode & "&title=Street+Map+for+" & s & "&nolocal=y") as string

Jon

What version of Panther are you using? Trying your code gives me the -1700 error again.

However, perversely, adding a tell application “Safari” | end tell with the open location in between them works. That’ll do for now, I guess!

  • padmavyuha

As I wrote above, 10.3.2. Here’s an even more streamlined version:

tell application "System Events" to tell (item 1 of (processes whose frontmost = true)) to keystroke "c" using command down
delay 1
set s to (get the clipboard) as string
set postCode to (change " " into "+" in s)
open location ("http://www.streetmap.co.uk/streetmap.dll?postcode2map?code=" & postCode & "&title=Street+Map+for+" & s & "&nolocal=y") as string

Jon

So you did - sorry. But your script still won’t work for me in iKey - maybe this is an iKey bug?

This works (the ‘get’ seemed redundant - doesn’t seem to make a difference to whether it writes to the clipboard or not):

tell application "System Events" to tell (item 1 of (processes whose frontmost = true)) to keystroke "c" using command down
delay 1
set s to the clipboard as string
set postCode to (change " " into "+" in s)
tell application "Safari" to open location "http://www.streetmap.co.uk/streetmap.dll?postcode2map?code=" & postCode & "&title=Street+Map+for+" & postCode & "&nolocal=y"

Though it’s still likely not to copy the highlighted text to the clipboard first - I usually have to do that first.

  • padmavyuha