Saturday, December 16, 2017

#1 2017-11-29 09:19:56 pm

cudaboy_71
Member
Registered: 2014-03-04
Posts: 20

http missing when passing string from AS to shell script

NOTE: the bbcode of this site is surrounding the urls in my AS code below with the {URL} and {/URL} brackets...those should not be there. The code looks fine except for those.

this is a weird one. but, perhaps just due to my inexperience

My script is much more advanced than what I'm posting below. But, I've simplified it to replicate the issue. But, all I'm doing is creating a variable in AS and passing it to the shell to do some AWK stuff. But, I've found the string isn't making it out of AS in tact.

The only difference between the following two snippets is I return the variable in AS in the first one. This returns the properly formatted URL with 'http' at the beginning.

Applescript:


set theString to "Frank%20Palmer%0James%20Hamilton"

set theURL to "[url]http://www.mywebsite.net/search=[/url]" & theString

return theURL

do shell script "theAddress=$" & theURL & "
echo 'the URL is' $theAddress"

In this second bit, I've only removed the return line so that shell echos back the variable. And, the 'http' is stripped off.
I'm scratching my head.  I don't know what is wrong here. Any suggestions?

Applescript:


set theString to "Frank%20Palmer%0James%20Hamilton"

set theURL to "[url]http://www.mywebsite.net/search=[/url]" & theString

do shell script "theAddress=$" & theURL & "
echo 'the URL is' $theAddress"

Last edited by cudaboy_71 (2017-11-29 09:20:29 pm)

Offline

 

#2 2017-11-30 04:43:05 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4456

Re: http missing when passing string from AS to shell script

Sorry about the BBCode problem. Ray does know about it and is talking to his site developer. One way round the problem is to break up URL strings in posted scripts so that the site softward doesn't recognise them as URLs.

The cure for the missing "http" is to use the quoted form of the URL text in the shell script:

Applescript:


set theString to "Frank%20Palmer%0James%20Hamilton"

set theURL to "http" & "://www.mywebsite.net/search=" & theString -- URL split to fool MacScripter's BBS software.

do shell script "theAddress=$" & quoted form of theURL & "
echo 'the URL is' $theAddress"

Or:

Applescript:


set theString to "Frank%20Palmer%0James%20Hamilton"

set theURL to "http" & "://www.mywebsite.net/search=" & theString

do shell script "theAddress=$" & quoted form of theURL & "
echo \"the URL is $theAddress\""
-- echo string in double quotes.


NG

Offline

 

#3 2017-11-30 12:15:54 pm

cudaboy_71
Member
Registered: 2014-03-04
Posts: 20

Re: http missing when passing string from AS to shell script

thanks. that did the trick.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)