alitaliano <> temporaire ? Do you come from valle d’aosta ? ;)
There is no need for GUI scripting. Since Safari 4 tabs are easily scriptable
set destFolder to POSIX path of (path to pictures folder as Unicode text) & "TEMPORAIRE:"
set {TID, text item delimiters} to {text item delimiters, "/"}
tell application "Safari"
repeat with aTab from 1 to (count tabs of window 1)
tell window 1 to set current tab to tab aTab -- go to next tab
set numberOfPictures to do JavaScript "document.images.length" in document 1 -- document 1 is always the visible tab
repeat with aPicture from 1 to numberOfPictures
set picURL to do JavaScript "document.images[" & ((aPicture - 1) as string) & "].src" in document 1
if picURL ends with "jpg" then
set fName to last text item of picURL
do shell script "curl -o " & quoted form of (destFolder & fName) & space & picURL
end if
end repeat
end repeat
end tell
set text item delimiters to TID
Note: Without any error handling images with same file name will overwrite existing ones
Hey StefanK, the legend !
No, I’m french :rolleyes:
Thank you so much for your reply !
But something is still wrong : the pictures save in “pictures folder” but not in the “Temporaire” folder.
I tried to add the possibility to close tab whent it’s been downloaded without result.
Can you help me again ? Thank you !
set destFolder to POSIX path of ((path to desktop as Unicode text) & "TEMPORAIRE:")
set {TID, text item delimiters} to {text item delimiters, "/"}
tell application "Safari"
repeat with aTab from 1 to (count tabs of window 1)
tell window 1 to set current tab to tab aTab -- go to next tab
set numberOfPictures to do JavaScript "document.images.length" in document 1 -- document 1 is always the visible tab
repeat with aPicture from 1 to numberOfPictures
set picURL to do JavaScript "document.images[" & ((aPicture - 1) as string) & "].src" in document 1
if picURL ends with "jpg" then
set fName to last text item of picURL
do shell script "curl -o " & quoted form of (destFolder & fName) & space & picURL
end if
end repeat
end repeat
end tell
set text item delimiters to TID
sorry, as we deal with POSIX paths the last character must be a slash.
The script closes every tab which doesn’t contain any images
set destFolder to POSIX path of (path to pictures folder as Unicode text) & "TEMPORAIRE/"
set {TID, text item delimiters} to {text item delimiters, "/"}
tell application "Safari"
repeat with aTab from 1 to (count tabs of window 1)
tell window 1 to set current tab to tab aTab -- go to next tab
set numberOfPictures to do JavaScript "document.images.length" in document 1 -- document 1 is always the visible tab
if numberOfPictures = 0 then tell window 1 to close current tab
repeat with aPicture from 1 to numberOfPictures
set picURL to do JavaScript "document.images[" & ((aPicture - 1) as string) & "].src" in document 1
if picURL ends with "jpg" then
set fName to last text item of picURL
do shell script "curl -o " & quoted form of (destFolder & fName) & space & picURL
end if
end repeat
end repeat
end tell
set text item delimiters to TID
Nope, it doesn’t work and I have the same error.
Pictures still save in the “pictures folder” in home though.
If you have time and patience to tell me why…
Anyways thank you so much to pay attention for a newbie like me !!