You made half point.
When the asker got your answer he said : OK, it works but it doesn't.
In fact we discovered that he was trying to save the contents of a page containing only a picture.
was treating every cases but he refused it so I grabbed a curl instruction borrowed from a Nigel Garvey's script and wrote :
#[SCRIPT]
# quelques instructions pour ouvrir la page de test
tell application "Safari"
activate
tell document 1
# Defines the URL for tests
set its URL to "
http://images.midilibre.fr/images/2013/12/26/des-habitants-de-pissevin-attendent-le-retour-de_766882_510x255.jpg"
delay 5
end tell
end tell
# Le véritable code
# set destFolder to path to desktop folder as text
set destFolder to path to documents folder as text
tell application "Safari"
activate
tell document 1
# comme vous voyez je suis ceinture et bretelles et je généralise l'emploi du préfixe its
set theURL to its URL
set theName to its name
end tell
end tell
# supprimons les éventuels : et / qui sont mal vus dans les noms de fichiers
set theName to my remplace(theName, ":/", "_") & ".jpg"
# construit le chemin du fichier à créer
set theFilePath to destFolder & theName
# il ne serait peut-être pas judicieux d'écraser un fichier homonyme
tell application "System Events" to set existe to exists disk item theFilePath
if not existe then
set posixFilePath to quoted form of POSIX path of theFilePath
do shell script "curl -L --user-agent 'Opera/9.70 (Linux ppc64 ; U; en) Presto/2.2.1' --url " & theURL & " -o " & posixFilePath
tell application "Finder"
reveal alias theFilePath
# activate
end tell
else
error "Le fichier « " & theFilePath & " » existe déjà !"
end if
#=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1}
set l to text items of t
set AppleScript's text item delimiters to d2
set t to "" & l
set AppleScript's text item delimiters to oTIDs
return t
end remplace
#=====
#[/SCRIPT]