Date
1 - 5 of 5
Advice required with cURL, please!
Brian Christmas
G’day scripters
I want to read a remote .txt file using cURL, and save the result to a variable, NOT a file.
If necessary, I want to add to that variable, and write it back to the remote file.
Just can’t get it right. Plenty of advice online on saving or transferring a FILE, but things get awkward when limited to a variable. Simply can’t find info!
The following doesn’t error, but also doesn’t save.
Can someone tell me how to go about the right cURL method, please?
Regards
Santa
try
say 0
do shell script " curl file_get_contents " & theCheckPath & " echo " & theEmailList
on error
say 0.1
set theEmailList to {}
end try
if (count of theEmailList) = 0 then set theEmailList to {}
say 1
set end of theEmailList to {{EmailAddress}, {businessName}}
say 2
do shell script "curl -T -d " & theEmailList & " --url " & theCheckPath
theEmailList
Brian Christmas
Steve, thanks for trying, but your code, and my slightly amended code, both return…
Can’t set end of "<!DOCTYPE html><html style=\"height:100%\"><head><title> 404 Not Found</title></head><body style=\"color: #444; margin:0;font: normal 14px/20px Arial, Helvetica, sans-serif; height:100%; background-color: #fff;\"><div style=\"height:auto; min-height:100%; \"> <div style=\"text-align: center; width:800px; margin-left: -400px; position:absolute; top: 30%; left:50%;\"><h1 style=\"margin:0; font-size:150px; line-height:150px; font-weight:bold;\">404</h1><h2 style=\"margin-top:20px;font-size: 30px;\">Not Found</h2><p>The resource requested could not be found on this server!</p></div></div></body></html>" to {{"ozsanta@..."}, {"meSelfSoftWare.com"}}.
What I want is the CONTENT of the file, not its properties, please?
AND, is my saving line correct?
I’m completely guessing, and Shane’s told me ‘DON’T GUESS!’, BUT I CAN’T WORK THE TERMINOLOGY OUT!.
What I THINK I’m doing wrong is addressing the .txt file in the wrong way. <p>The resource requested could not be found on this server!</p> I have no idea what I’m supposed to do, and have read the cURL help and examples over and over. I just cannot wrap my mind around what I’m doing wrong!
Regards
Santa
property theEmailList : {}
set theCheckPath to "http://meselfsoftware.com/xxxxx%20list/xxxx%20Email.txt/“ # Modified for posting
set (my theEmailList) to {}
try
say 0
set (my theEmailList) to do shell script "curl file_get_contents " & theCheckPath
# set (my theEmailList) to do shell script "curl " & theCheckPath # Steve’s script
# do shell script "curl file_get_contents " & theCheckPath & " echo " & (my theEmailList)
on error
say 0.1
set (my theEmailList) to {}
end try
if (count of (my theEmailList)) = 0 then set (my theEmailList) to {}
say 1
try
set end of theEmailList to {{EmailAddress}, {businessName}}
on error errmsg
set end of theEmailList to {{EmailAddress}, {businessName}}
tell application "System Events" to display dialog errmsg
end try
say 2
try
do shell script "curl -T -d " & (my theEmailList) & " --url " & theCheckPath
on error errmsg
tell application "System Events" to display dialog errmsg
end try
theEmailList
I’m deriving the path from this… which is in the same site folder
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>URL</key>
</dict>
</plist>
The Site Inspector say their folder is /home/meselfso
On 23 Oct 2017, at 1:50 pm, Steve Mills <sjmills@...> wrote:On Oct 22, 2017, at 20:53:06, Brian Christmas <ozsanta@...> wrote:
G’day scripters
I want to read a remote .txt file using cURL, and save the result to a variable, NOT a file.
set x to do shell script "curl " & theURL
--
Steve Mills
Drummer, Mac geek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript-users@...)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/applescript-users/ozsanta%40gmail.com
Archives: http://lists.apple.com/archives/applescript-users
This email sent to ozsanta@...
2551phil
On 23 Oct 2017, at 10:44, Brian Christmas <ozsanta@...> wrote:<head><title> 404 Not Found
This tells you that the url string you’re sending is wrong.
Start with a simple one-liner like this:
do shell script "curl " & “https:…/../.html”
until it works. Then build up from that.
Also, you’re getting the error message because you’re illegally trying to use ‘set end of’ on a string instead of on a list.
And why are you calling display dialog from system events?
Best
Phil
@sqwarq
Brian Christmas
Thank you Phil & Steve.

There seems to be some sort of underlying problem.
To start, I’ll make sure you know what I’m trying to do.
On my home folder of my website I have two websites…
I have created a folder at the same level, ‘Email List’
In this I have created a txt file, 'Used Emails.txt', using the file creator of Rapid Weaver.
I want to read that txt file, check there is no more than 2 given copies of a particular email address in it, and if not, add the email address and the company name at the end of the text file, as a list.
I’ve tried following your advice, and also tried to open the page, and the folder, and the txt file, using Safari.
However, I’m getting a double colon in the Safari error message, and simply don’t know why! (/http/::)
I’ve also ensured I have full stop where every name on the site lists as a space.
And, Phil, using System Events is a habit, as I often write and text ASCObjC code in Script Editor, or Script Debugger, and just copy and paste when it’s working. Use the same variables. Also why I used the ‘my ‘. I’ve just found it a good habit to get into.
tell application "Safari"
open theCheckPath
end tell
try
# set (my theEmailList) to do shell script "curl " & theCheckPath
# set (my theEmailList) to do shell script "curl file_get_contents " & theCheckPath
# do shell script "curl file_get_contents " & theCheckPath & " echo " & (my theEmailList)
set theEmailList to do shell script "curl " & theCheckPath
on error
say 0.1
set theEmailList to {}
end try
try
if kind of theEmailList is not list then set theEmailList to {}
on error errmsg number errnum
if errnum = -1728 then set theEmailList to {}
end try
try
set end of theEmailList to {{EmailAddress}, {businessName}}
on error errmsg
set end of theEmailList to {{EmailAddress}, {businessName}}
tell application "System Events" to display dialog errmsg
end try
say 2
try
do shell script "curl -T -d " & theEmailList & " --url " & theCheckPath
on error errmsg
tell application "System Events" to display dialog errmsg
end try
theEmailList
2551phil
On 23 Oct 2017, at 12:18, Brian Christmas <ozsanta@...> wrote:And, Phil, using System Events is a habit, as I often write and text ASCObjC code in Script Editor, or Script Debugger, and just copy and paste when it’s working. Use the same variables. Also why I used the ‘my ‘. I’ve just found it a good habit to get into.
Display Dialog has absolutely nothing to do with System Events. It’s defined in Standard Additions. While a single invocation like this probably doesn’t do any harm other than introduce an unnecessary delay, it could well cause you problems if you’re doing that repeatedly or excessively in your 10000+ line scripts.
‘my’ is a synonym of the ‘me’ keyword. Unless you enjoy bugs, you shouldn’t be using it habitually like some magic voodoo, but only when it’s required. For correct use, see the AppleScript Language Guide under the section ‘The it and me keywords’.
Best
Phil
@sqwarq