Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Image view - checking dropped image



Doh!

Silly of me... I should have thought of it before.
Just using (the line below) does the job:

set droppedImg to droppedImgPath as POSIX file

instead of the longwinded columnDelim routine

This time I'll remember not to complicate things!

> Hi all,
>
> Just a quick question as to how I can successfully examine if a "about
> to be dropped" file is actually an image.
>
> Based on the Drag n drop example, I've come up with the following which
> works, EXCEPT that because the path returned by the "prepare drop" and
> "drop" event handlers is slash delimited, I need (I think!) to convert
> it to a column delimited path (taking into account the Volumes), and
> this process seems to hang the application, although it does eventually
> come back to life after the spinning beachball, and correctly determine
> if it is a valid image file. I used "Image Capture Scripting" to test
> opening the file, because I'll be using the app again after.
>
> Is there a better way (quicker... no hangups!) of verifying the
> validity of the dropped file?
>
> property droppedImgPath : ""
> --
> on awake from nib theObject
> tell theObject to register drag types {"image", "pict image", "file
> names", "color"}
> end awake from nib
> --
> on drop theObject drag info dragInfo
> set theImage to load image droppedImgPath
> set image of theObject to theImage
> delete theImage
> set preferred type of pasteboard of dragInfo to ""
> return true
> end drop
>
> on prepare drop theObject drag info dragInfo
> set dataTypes to types of pasteboard of dragInfo
> if "file names" is in dataTypes then
> set preferred type of pasteboard of dragInfo to "file names"
> set thePaths to contents of pasteboard of dragInfo
> set droppedImgPath to (item 1 of thePaths)
>
> set droppedImg to my columnDelim(droppedImgPath) --this is where the
> path is converted to column delimited
>
> tell application "Image Capture Scripting"
> try
> set this_image to open file droppedImg
> close this_image
> return true
> on error errMsg
> tell me to log errMsg
> return false
> end try
> end tell
> end if
> else
> return false
> end if
> end prepare drop
>
> on columnDelim(thePath)
> set thePath to (POSIX path of thePath) as string
> set a to thePath
> set a to (rest of (every item of a)) as string
> tell application "Finder"
> set b to name of startup disk
> end tell
> if a contains "Volumes" then
> set a to items 10 thru (count a) of a as string
> else
> set a to b & a
> end if
> return a
> end columnDelim
>
> Once again, any pointers much appreciated!
--
DizzyPenguin * autoMAC-it
mailto:email@hidden
visit: http://www.dizzypenguin.com/automac-it/
_______________________________________________
applescript-studio mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-studio
Do not post admin requests to the list. They will be ignored.

References: 
 >Image view - checking dropped image (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.