Add Studio Log to My Yahoo

Another Method of Getting Image Info in Safari with AppleScript

In the following script, an image must be the open in the front window of Safari. One method is to Control-click an image in a web page and another is to drag and drop the image into the browser window. The run this script. If the image is a remote file, a copy is downloaded to the temporary items folder with the cURL shell command. If the image is local, the local copy is used. The script will obtain the width, height and data size of the image by using the Image Capture Scripting Scripting Addition and display it in a dialog box. Click on "Copy to Desktop" will copy the file from it current location to the desktop with the cp shell command.

tell application "Safari"
set g to URL of document 1
end tell

set text item delimiters to "/"
set fname to last text item of g
set protocol to first text item of g
set text item delimiters to ""
if protocol is equal to "http:" then
set f to ((path to temporary items folder from user domain) as string) & fname
set h to POSIX path of f
set cmd to "curl -o '" & h & "' " & g
set t to do shell script cmd
getImageInfo(g, h, fname)
else
set strC to count of g
set h to characters 8 thru strC of g as string
getImageInfo(g, h, fname)
end if

on getImageInfo(g, h, fname)
set macImage to h as POSIX file
set theInfo to info for macImage
set wholeBytes to size of theInfo
set theBytes to round (wholeBytes / 1000)
tell application "Image Capture Scripting"
set this_image to open macImage
set the image_width to the width of this_image
set the image_height to the height of this_image
close this_image
end tell
tell application "Safari"
activate
set infoDisplay to display dialog "URL: " & g & return & return & h & return & "Size: " & theBytes & " KB" & return & "Width: " & image_width & " Height: " & image_height buttons {"Copy to Desktop", "OK"} default button 2 with icon note giving up after 10
end tell
if button returned of infoDisplay is "Copy to Desktop" then
set dtop to (path to desktop from user domain) as string
set udtop to POSIX path of dtop
set destination_file to udtop & fname as string
set cmd to "cp '" & h & "' '" & destination_file & "'" as string
do shell script cmd
end if
end getImageInfo

Studio Log

Back