How to save to a specific folder the images from a webpage?
I hope to open the url as in a field in a FMP12 db
Renamed the collected image according to another field in the same FMP12 db
Each Url only has one image. No text or links, just the photo
I can do it manually just clicking the image it will be good to createa a loop from the FMP12 DB
Thanks
Export field contents from Filemaker as txt (Ofcourse, there must be a direct way to access records from Filemaker but I haven’t used it)
Use loop in applescript using curl to download the images and
example:
Also, the example used has an extension like jpg, some changes may have to be made if your url does not end with image extension.
Thanks a lot … however I am an old newbbie (yrs 75) so I learn slowly would help a bit more:
This what I use to get the txt file:
set specificFolder to (choose folder) -- *** destination folder ***--
tell application "FileMaker Pro Advanced"
tell database "GraduatesA"
tell table 1
set theID to field "STID" -- gets ID
set theDate to field "Date" -- get Dates
do script "exportID_Dates" --exports all StudentIDs, Class, PictureURL
end tell
end tell
end tell
however I don’t kno where to place your kind suggestion or if this script just doesn’t function at all
I get a folder with an UTF-8 Palin txt file as follows
StudentID tab Class tab Date tab photoURL caRRIAGERETURN
5600511 (TAB) GraduatesA13 (TAB) 01052013 (TAB) www.this_site/img01.jpg
5600423 (TAB) GraduatesA13 (TAB) 01052013 (TAB) www.this_site/img02.jpg
and so on
how to create the loop?
The script allows me to choose a folder and place the text file with the various infos but how to use curl in connection with this?
My students are many and often the image name will be the same while the photo is different (this is an issue with digital photography: once reformatting they assign the name to the pics resarting with DSC0000.jpg)
Regards
Thanks
Hey There,
You need to show us what you want your output to look like and a fully representative sample of the input.
I don’t think I’d use a loop with curl. Instead I’d massage your output data from FM and assemble a curl config file:
FILE
url = http://members.aceweb.com/randsautos/photogallery/ferrari/enzo/Ferrari-Enzo-001.jpg
output = /Users/chris/Pictures/New/F1.jpg
url = http://members.aceweb.com/randsautos/photogallery/ferrari/enzo/Ferrari-Enzo-002.jpg
output = /Users/chris/Pictures/New/F2.jpg
EOF
Massage your data to look like this (without the ITEMS).
Then write it to a file and run curl with the -K switch.
curl -L -K, --config
Or
Shoot the data to curl from standard in:
echo | curl -L -K -
This job should be fairly simple.
More data please.
If I understand exactly (I wasn’t born in English and I am not too familiar with computer specific idiom):
the FMP exported text outputs are a sequence of lines always according to this pattern.
StudentID (tab) Class (tab) date (tab) URL Carriage Return
Each file has different lines and should go to different folders
example
5600511 (TAB) GraduatesA13 (TAB) 01052013 (TAB) www.this_site/img01.jpg
5600423 (TAB) GraduatesA13 (TAB) 01052013 (TAB) www.this_site/img02.jpg
the url: www.this_site/GraduatesA13/img01.jpg
the output = /Users/danwan/Classes2013/2nd/GraduatesA13/5600511-01052013.jpg
the url: www.this_site//GraduatesA13/img02.jpg
ùthe output = /Users/danwan/Classes2013/2nd/GraduatesA13/5600423-01052013.img02.jpg
the webpages www.this_site/GraduatesA13/img01.jpg etc.
only contains the image, no text no other data but the “img01.jpg” reference
Hope I understood
Regards
Disclosure: I am a newbie.
Warning: You must not have a file named theConfigFile.txt on your Desktop. It will be replaced if it exists.
Here’s the sample tab separated file (based on your data pattern) which this script uses:
http://www.2shared.com/file/ng9Kkp5X/Untitled.html
Place the file on the desktop and run this script.
do shell script "echo > ~/Desktop/theConfigFile.txt"
set thePath to POSIX path of (path to desktop as Unicode text) & "untitled.tab"
set theText to readFile(thePath)
set theList to {}
set countOfParagraphs to count of paragraphs in theText
repeat with i from 1 to countOfParagraphs
set theLine to paragraph i of theText
set end of theList to theLine
end repeat
set countOfListItems to (count of theList) - 1
repeat with i from 1 to countOfListItems
set theLine to item i of theList
-- display dialog theLine
set AppleScript's text item delimiters to tab
set theName1 to text item 3 of theLine
set theName2 to text item 2 of theLine
set theURL to text item 4 of theLine
set AppleScript's text item delimiters to ""
set theURLcmd to "echo url = " & theURL & " >> ~/Desktop/theConfigFile.txt"
do shell script theURLcmd
set theOutput to "~/Desktop/" & theName1 & "." & theName2 & ".jpg"
set theOutputcmd to "echo output = " & theOutput & " >> ~/Desktop/theConfigFile.txt"
do shell script theOutputcmd
end repeat
set thecmd to "curl -L -K, --config ~/Desktop/theConfigFile.txt"
do shell script thecmd
on readFile(unixPath)
set foo to (open for access (POSIX file unixPath))
set txt to (read foo for (get eof foo) as «class utf8»)
close access foo
return txt
end readFile
If the above script does work you just to have replace the untitled.tab file with your .tab file and give the desired location for the output file which currently is “~/Desktop”.
The version below does not require a config file. I don’t know why this should not be used. Seems to work fine.
set thePath to POSIX path of (path to desktop as Unicode text) & "untitled.tab"
set theText to readFile(thePath)
set theList to {}
set countOfParagraphs to count of paragraphs in theText
repeat with i from 1 to countOfParagraphs
set theLine to paragraph i of theText
set end of theList to theLine
end repeat
set countOfListItems to (count of theList) - 1
repeat with i from 1 to countOfListItems
set theLine to item i of theList
-- display dialog theLine
set AppleScript's text item delimiters to tab
set theName1 to text item 3 of theLine
set theName2 to text item 2 of theLine
set theURL to text item 4 of theLine
set AppleScript's text item delimiters to ""
set thePath to "~/Desktop/" & theName1 & "." & theName2 & ".jpg"
set thecmd to "curl -o " & thePath & " " & theURL
do shell script thecmd
end repeat
on readFile(unixPath)
set foo to (open for access (POSIX file unixPath))
set txt to (read foo for (get eof foo) as «class utf8»)
close access foo
return txt
end readFile
As usual there’s more than one way to do it.
Here’s why I’d use a config file, or in this case a pseudo-file passed via std-in.
set _cmd to "
rptFile=~/Desktop/fmpClassReport.txt;
dnldFldr=~/Documents/Classes2013/2nd/;
awk -v dnldFldr=\"$dnldFldr\" '{ print \"url = http://\"$4\"\\noutput = \"dnldFldr$2\"/\"$1\"-\"$3\".jpg\" }' \"$rptFile\" \\
| curl -L --create-dirs --user-agent 'Opera/9.70 (Linux ppc64 ; U; en) Presto/2.2.1' -K -
"
do shell script _cmd
The script requires that the file ‘fmpClassReport.txt’ exist on the desktop.
It will build the download directory structure as necessary.
I’m not appending the original file names of the images, as the OP indicated these were arbitrary.
It could be a one-liner, but it would be more difficult to maintain.
Personally I’d write a function for my bash profile and run it from the Terminal to get progress indicators, but it works either way.
Now then. If I was going to do this with Applescript I’d use the Satimage.osax to do the heavy lifting.
http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html
try
set _file to ((path to desktop as text) & "fmpClassReport.txt")
try -- Make sure the report file exists.
set _file to alias _file
on error
error "The file fmpClassReport.txt is not on the Desktop!"
end try
set _base to POSIX path of (path to "docs" as text) & "Classes2013/2nd/"
set _config to read _file using delimiter linefeed
set _config to change "^([^\\t]+)\\t([^\\t]+)\\t([^\\t]+)\\t(.+/([^/]+$))" into ¬
"url = \"http://\\4\"\\noutput = \"" & _base & "\\2/\\1-\\3.\\5\"" in ¬
_config with regexp
set _config to join _config using linefeed
set _cmd to "echo " & quoted form of _config & " | curl -Ls --create-dirs -A 'Opera/9.70 (Linux ppc64 ; U; en)' -K -"
do shell script _cmd
on error e number n
beep
set e to e & return & return & "Num: " & n
tell me to set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
if button returned of dDlg = "Copy" then set the clipboard to e
end try
This one has a little error-checking built in to make sure the fmpClassReport.txt file exists on the desktop.
what is this in plain english?
Hey There,
I’m sorry it’s taken me so long to get back to this.
[code]rptFile=~/Desktop/fmpClassReport.txt;
dnldFldr=~/Documents/Classes2013/2nd/;
awk -v dnldFldr=“$dnldFldr” ‘{ print “url = http://”$4"\noutput = “dnldFldr$2”/“$1”-“$3”.jpg" }’ “$rptFile” |
curl -L --create-dirs --user-agent ‘Opera/9.70 (Linux ppc64 ; U; en) Presto/2.2.1’ -K -
awk == A Unix executable.
-v dnldFldr=“$dnldFldr” == Make an awk variable from a shell variable.
‘{ == Start of the Awk program.
print == Print to stdout
“url = http://” == Literal string.
$4 == Field 4 (Awk uses whitespace as a default delimiter).
"\noutput = " == Interpolated string with embedded linefeed.
dnldFldr == Awk variable for the download folder.
$2 == Field 2
“/” == Literal string.
$1 == Field 1
“-” == Literal string.
$3 == Field 3
“.jpg” == Literal string.
}’ == End of the Awk program.
“$rptFile” == An interpolated variable corresponding to the input file path.
| == Pipe output of Awk to curl
curl
-L == Follow Redirects.
–create-dirs == Create directories as nessary for output
–user-agent == Spoof a user-agent other than curl (some websites don’t like curl).
-K - == Use config file » trailing ‘-’ means to take input from stdin instead of a file.[/code]
(Hm. Code is supposed to produce a monospaced font…)
I’ve removed the line-continuation character from between the awk and curl lines (‘\’), because as I learned recently a pipe works fine when the next command is on the next line.
Awk reads the FMP-output file line-by-line and transforms it into a proper curl config file which is then piped to curl.