`osascript -e` in perl: a problem

wiz

Registered
it dosen't work correctly.
you might want to try it out your self.

running it from the command prompt works as it should, displaying the dialogue and everything. But setting the file to open with "/Applications/Utilities/Launcher" works but dosen't display the results correctly.

i wrote this script in a hurry though,, not sure if the syntax is correct. (but i'm sure it prints out the right results, in the terminal al least.)

<layer z-index=2><font size=2 face="courier"><hr>#!/usr/bin/perl<br><br>use&nbsp;warnings&#059;<br>use&nbsp;strict&#059;<br><br>our&nbsp;$query&nbsp;=&nbsp;system&#040;&quot;wget&nbsp;-q&nbsp;-O&nbsp;/dev/stdout&nbsp;&apos;http&#058;//checkip&#046;dyndns&#046;org/&apos;&quot;&#041;&#059;<br><br>our&nbsp;&#040;$extIP&#041;&nbsp;=&nbsp;$query&nbsp;=~&nbsp;/&#046;*Current&nbsp;IP&nbsp;Address&#046;+?&#040;\d{1,3}\&#046;\d{1,3}\&#046;\d{1,3}\&#046;\d{1,3}&#041;&#046;*/i&#059;<br>&nbsp;&nbsp;&nbsp;&nbsp;chomp&nbsp;$extIP&#059;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>our&nbsp;&#040;$hostname&#041;&nbsp;=&nbsp;$query&nbsp;=~&nbsp;/&#046;*hostname&#058;&#046;&#040;&#046;*&#041;/i&#059;<br>&nbsp;&nbsp;&nbsp;&nbsp;chomp&nbsp;$hostname&#059;<br><br>our&nbsp;$localhostname&nbsp;=&nbsp;`hostname`&#059;<br>&nbsp;&nbsp;&nbsp;&nbsp;chomp&nbsp;$localhostname&#059;<br>&nbsp;&nbsp;&nbsp;<br>our&nbsp;$intIP&nbsp;=&nbsp;`ipconfig&nbsp;getifaddr&nbsp;en0`&#059;<br>&nbsp;&nbsp;&nbsp;&nbsp;chomp&nbsp;$intIP&#059;<br><br>our&nbsp;$result&nbsp;=&nbsp;&lt;&lt;&quot;__END__&quot;&#059;<br><br>Dynamic&nbsp;Hostname&nbsp;&nbsp;&nbsp;&nbsp;&#058;&nbsp;&nbsp;$hostname<br>Local&nbsp;Hostname&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#058;&nbsp;&nbsp;$localhostname<br>External&nbsp;IP&nbsp;address&nbsp;&#058;&nbsp;&nbsp;$extIP<br>Internal&nbsp;IP&nbsp;address&nbsp;&#058;&nbsp;&nbsp;$intIP<br><br>__END__<br><br>print&nbsp;$result&#059;<br><br>our&nbsp;$value&nbsp;=&nbsp;`osascript&nbsp;-e&nbsp;&apos;tell&nbsp;app&nbsp;&quot;Finder&quot;&nbsp;\n&nbsp;activate&nbsp;\n&nbsp;set&nbsp;value&nbsp;to&nbsp;&quot;$result&quot;&nbsp;\n&nbsp;display&nbsp;dialog&nbsp;value&nbsp;buttons&nbsp;&quot;Ok&quot;&nbsp;\n&nbsp;end&nbsp;tell&apos;`&#059;<br><br>#print&nbsp;$value&#059;<hr></font></layer>
 
Probably a path problem, i.e. the osascript command is not found. Try using the absolute path.
 
Originally posted by rhg
Probably a path problem, i.e. the osascript command is not found. Try using the absolute path.

nope it works,,

just that it displays

dynamic hostname :
local hostname : macosx.local
External IP :
internal IP : 192.168.1.101


what happened to the rest of the data?
 
As I said, it is a path issue. All the data which is to be retrieved with your wget call is missing, so I would suggest to use the absolute path to wget instead (i.e. the wget command is obviously not found when your script is invoked with the Launcher utility).
 
Originally posted by rhg
As I said, it is a path issue. All the data which is to be retrieved with your wget call is missing, so I would suggest to use the absolute path to wget instead (i.e. the wget command is obviously not found when your script is invoked with the Launcher utility).

nope no luck! (i've tried.. same thing)

any ideas?
 
Another point. Do you think it's correct to use /dev/stdout in your wget invocation? man wget suggests to use - as stdout, i.e.:
wget -q -O - 'http://checkip.dyndns.org/'
 
Originally posted by wiz
same error,, i've tried. oh well. i guess we could call it a bug!


LOL WOW... FINALLY i got it to work...

<font size=2 face="courier"><hr>#!/usr/bin/perl<br><br>use&nbsp;warnings&#059;<br>use&nbsp;strict&#059;<br><br>our&nbsp;$query&nbsp;=&nbsp;`/sw/bin/wget&nbsp;-q&nbsp;-O&nbsp;/dev/stdout&nbsp;&apos;http&#058;//checkip&#046;dyndns&#046;org/&apos;`&#059;<br><br>our&nbsp;&#040;$extIP&#041;&nbsp;=&nbsp;$query&nbsp;=~&nbsp;/&#046;*Current&nbsp;IP&nbsp;Address&#046;+?&#040;\d{1,3}\&#046;\d{1,3}\&#046;\d{1,3}\&#046;\d{1,3}&#041;&#046;*/i&#059;<br>&nbsp;&nbsp;&nbsp;&nbsp;chomp&nbsp;$extIP&#059;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>our&nbsp;&#040;$hostname&#041;&nbsp;=&nbsp;$query&nbsp;=~&nbsp;/&#046;*hostname&#058;&#046;&#040;&#046;*&#041;/i&#059;<br>&nbsp;&nbsp;&nbsp;&nbsp;chomp&nbsp;$hostname&#059;<br><br>our&nbsp;$localhostname&nbsp;=&nbsp;`hostname`&#059;<br>&nbsp;&nbsp;&nbsp;&nbsp;chomp&nbsp;$localhostname&#059;<br>&nbsp;&nbsp;&nbsp;<br>our&nbsp;$intIP&nbsp;=&nbsp;`ipconfig&nbsp;getifaddr&nbsp;en0`&#059;<br>&nbsp;&nbsp;&nbsp;&nbsp;chomp&nbsp;$intIP&#059;<br><br>our&nbsp;$result&nbsp;=&nbsp;&lt;&lt;&quot;__END__&quot;&#059;<br><br>Dynamic&nbsp;Hostname&nbsp;&nbsp;&nbsp;&nbsp;&#058;&nbsp;&nbsp;$hostname<br>Local&nbsp;Hostname&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#058;&nbsp;&nbsp;$localhostname<br>External&nbsp;IP&nbsp;address&nbsp;&#058;&nbsp;&nbsp;$extIP<br>Internal&nbsp;IP&nbsp;address&nbsp;&#058;&nbsp;&nbsp;$intIP<br><br>__END__<br><br>print&nbsp;$result&#059;<br><br>our&nbsp;$value&nbsp;=&nbsp;`osascript&nbsp;-e&nbsp;&apos;tell&nbsp;app&nbsp;&quot;Finder&quot;&nbsp;\n&nbsp;activate&nbsp;\n&nbsp;set&nbsp;value&nbsp;to&nbsp;&quot;$result&quot;&nbsp;\n&nbsp;display&nbsp;dialog&nbsp;value&nbsp;buttons&nbsp;&quot;Ok&quot;&nbsp;\n&nbsp;end&nbsp;tell&apos;`&#059;<br><br>#print&nbsp;$value&#059;<hr></font>
 
now i have been modifying the code several times over,, thus the first posted code is not really the original.

but it seems to me the final code is so much similar to The Orginal... I'm not quite sure whats going on.. but it works now... that's all that matters

but i tell you, i'm sure this is what i first wrote. It didn't work then..

the only difference between now and then is that i update the os to 10.2.6!!!
 
Back
Top