The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   The Coat Room (http://hintsforums.macworld.com/forumdisplay.php?f=8)
-   -   Have Applescript, will travel... (http://hintsforums.macworld.com/showthread.php?t=76158)

Jay Carr 08-03-2007 03:50 AM

Quote:

Originally Posted by ThreeDee (Post 398009)
After learning AS, you can make fully working programs (menus, buttons, windows) in Xcode with AppleScript Studio.

BTW, People don't usually type the abbreviation of AppleScript Studio.

*Giggle* (my wife still gets mad at me for doing that too...)

Um, out of curiosity, how does one go about doing that? I could see me doing that with Java or even learning object-c to do it. Why would anyone use AppleScript, wouldn't it be considerably slower?

NovaScotian 08-03-2007 12:53 PM

Yes it's often slower that C, but not slower than Java typically. People do it because they want to write an app that involves a good deal of interaction with other applications and they want easy access to Apple Events.

tlarkin 08-03-2007 01:12 PM

can you make an apple script that transfers money from your bank account to mine?;)

I would look into making apple scripts to automate certain mundane tasks, like burning a CD, or composing an email or anything that would require some sort of manual data entry.

schneb 08-03-2007 07:14 PM

Quote:

Originally Posted by NovaScotian (Post 397995)
Looking into this, it's not actually hard. The difficulty will be parsing your comment into appropriate IPTC categories, unless you want only one or your comments are particularly well organized.

Reading the comment is:

tell app "Finder" to set cmt to comment of an_alias_to_a_commented_file

standard IPTC categories include:

Caption, Caption_writer, Headline, Instructions, Byline, Byline_Title, Credit, Source, title, unknown1, City, State, Country, reference_, Categories, Supplemental_Categories, unknown2, Keywords, Copyright_notice, _URL, event_, people, itemlist

GraphicConverter can set those individually, but be warned that setting overwrites anything already there.

I only want my Spotlight words to be written in the IPTC Comments box so that I can search my photos in Windows. I have an Automator Action that does it, unfortunately, it uses Photoshop to resave the photo with no way to adjust the JPEG settings! So it saves it as a small, low quality image. Grrrr. I tried saving the photo as another file, but now my "created" dates are messed up, and all my Spotlight comments are gone.

GraphicConverter would be just fine as long as it does not mess with the photo itself. Is that possible? I have both GraphicConverter and the latest Photoshop if that helps. All I want is a batch application that will "Copy Spotlight Comments" then "Paste results in IPTC comments".

You would not believe how hard such a thing is to find!

mark hunte 08-03-2007 08:04 PM

I wrote a script a while back see this thread on bbs.applescript.net .

It uses GraphicConverter to write IPTC from user input, But is should be very easy to convert it to your needs

NovaScotian 08-03-2007 08:16 PM

Hi Schneb;

This should do it (try it on a duplicate set, of course):

Code:

set F to choose folder
tell application "Finder"
        try
                set P to files of entire contents of F as alias list -- digs down through enclosed folders
        on error -- only one file found in chosen folder; a bug for as alias list
                set P to files of entire contents of F as alias as list -- deals with only one
        end try
        set K to {"GIF document", "GIF Image", "JPEG document", "JPEG Image", "PNG document", "TIFF document", "TIFF Image"} -- should include your photos
        repeat with I in P -- iterate through the pics
                if kind of F is in K then
                        set C to comment of F -- get the comment from the Finder
                        tell application "GraphicConverter" to set file iptc of F to {C} -- set it with GC
                end if
        end repeat
end tell

To check a file use:

Code:

set F to choose file of type {"public.image"} without invisibles with prompt "Choose a single image"
tell application "GraphicConverter" to get file iptc of F


schneb 08-06-2007 01:32 PM

Thanks NovaScotian, I gave it a try and it did not work. I made sure GraphicsCoverter was running and tried again--nothing. I then changed the application to Adobe Photoshop, and still, no result. Sigh...

mark hunte 08-06-2007 01:51 PM

Quote:

Originally Posted by schneb (Post 398957)
Thanks NovaScotian, I gave it a try and it did not work. I made sure GraphicsCoverter was running and tried again--nothing. I then changed the application to Adobe Photoshop, and still, no result. Sigh...

It will depend also on your version of GC.

update to the latest version and try again.

Also, I finder when i use my script to do this, its best that GC is running before I run the script.

NovaScotian 08-06-2007 02:11 PM

Quote:

Originally Posted by schneb (Post 398957)
Thanks NovaScotian, I gave it a try and it did not work. I made sure GraphicsCoverter was running and tried again--nothing. I then changed the application to Adobe Photoshop, and still, no result. Sigh...

Did Not Work is not quite a rich enough description, Schneb. How did it fail? Did it not compile? Run but do nothing? Give you an error message?

Try this on one of your files and tell me what K is. Perhaps I've got the kinds wrong.

Code:

tell application "Finder" to set K to kind of (choose file without invisibles)

schneb 08-06-2007 02:12 PM

Sorry about that. Definitely not enough input there.

It compiled OK, I ran it, it asked for a folder, I gave it a folder, it ran, but no comments were transferred. No errors.

The result of your script is "Adobe Photoshop JPEG file"

Can you tell it to just accept whatever it is? I do have a few audio files and movie files, but it can just ignore those. I believe I only have the following in my archive... JPEG, MOV, MP3. About 90% is JPEG.

NovaScotian 08-06-2007 02:26 PM

Quote:

Originally Posted by schneb (Post 398967)
Sorry about that. Definitely not enough input there.

It compiled OK, I ran it, it asked for a folder, I gave it a folder, it ran, but no comments were transferred. No errors.

What did the little script for kind say, what version of GC are you using, and by "nothing was written" do you mean that the test script below returned nada?

Code:

set F to choose file of type {"public.image"} without invisibles with prompt "Choose a single image"
tell application "GraphicConverter" to get file iptc of F


schneb 08-06-2007 05:37 PM

Quote:

Originally Posted by NovaScotian (Post 398974)
What did the little script for kind say, what version of GC are you using, and by "nothing was written" do you mean that the test script below returned nada?

Sorry, was not sure what to do with that code. But I did give it a try and I got an error message.

"GraphicConverter got an error: An error of type -2 has occurred"

I then came to find out that any photo file that did not have any IPTC text written will give the error above. I put in some IPTC text via Photoshop CS and got the following output...
{"Emma with Robert, Aunt Mary and others.", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "-1", "", "", "", "", ""}

NovaScotian 08-06-2007 06:51 PM

I've added Adobe Photoshop JPEG file to the list (only Adobe would stick it that way; jpeg is jpeg)

Code:

set F to choose folder
tell application "Finder"
        try
                set P to files of entire contents of F as alias list -- digs down through enclosed folders
        on error -- only one file found in chosen folder; a bug for as alias list
                set P to files of entire contents of F as alias as list -- deals with only one
        end try
        set K to {"GIF document", "GIF Image", "JPEG document", "JPEG Image", "PNG document", "TIFF document", "TIFF Image", "Adobe Photoshop JPEG file"} -- should include your photos
        repeat with I in P -- iterate through the pics
                if kind of F is in K then
                        set C to comment of F -- get the comment from the Finder
                        tell application "GraphicConverter" to set file iptc of F to {C} -- set it with GC
                end if
        end repeat
end tell


schneb 08-06-2007 07:03 PM

I'm still not getting anything to write to the IPTC.

Not sure if GraphicConverter recognizes just iptc as anything. Should there be any kind of other parameter to tell it just where in the iptc--such as "description"?

Note: The following only returns the Spotlight Comments of the folder, and not the content of the files therein...

Code:

set F to choose folder
tell application "Finder"
        try
                set P to files of entire contents of F as alias list -- digs down through enclosed folders
        on error -- only one file found in chosen folder; a bug for as alias list
                set P to files of entire contents of F as alias as list -- deals with only one
        end try
        repeat with I in P -- iterate through the pics
                set C to comment of F -- get the comment from the Finder
                return C
        end repeat
end tell

Could it be that the code for determining the file type was only seeing the folder, and thereby stopped there?

Note, I changed "set C to comment of F" to "set C to comment of I" and got a better result.

The following script gave an error...

Code:

set F to choose folder
tell application "Finder"
        try
                set P to files of entire contents of F as alias list -- digs down through enclosed folders
        on error -- only one file found in chosen folder; a bug for as alias list
                set P to files of entire contents of F as alias as list -- deals with only one
        end try
        repeat with I in P -- iterate through the pics
                set C to comment of I -- get the comment from the Finder
                tell application "GraphicConverter" to set file iptc of F to {C} -- set it with GC
        end repeat
end tell

The error was "GraphicConverter got an error: An error of type -3 has occurred.

NovaScotian 08-06-2007 07:27 PM

Ahh, Schneb; apologies -- a bug. Change the F in the line below to an I

set C to comment of F -- get the comment from the Finder should be
set C to comment of I -- get the comment from the Finder

schneb 08-06-2007 07:35 PM

Yes, as well as the next line, correct?

set C to comment of I -- get the comment from the Finder
tell application "GraphicConverter" to set file iptc of I to {C} -- set it with GC

It's running without errors, however, the comments are not being written to the IPTC. Does it need a parameter to say "where" in IPTC?

I definitely feel bad about hijacking Zalister's post here. I will write up a new question so we can transfer this exchange there.

Sorry Zalister!!

NovaScotian 08-06-2007 07:46 PM

Quote:

Originally Posted by schneb (Post 399054)
Yes, as well as the next line, correct?

set C to comment of I -- get the comment from the Finder
tell application "GraphicConverter" to set file iptc of I to {C} -- set it with GC

It's running without errors, however, the comments are not being written to the IPTC. Does it need a parameter to say "where" in IPTC?

I definitely feel bad about hijacking Zalister's post here. I will write up a new question so we can transfer this exchange there.

Sorry Zalister!!

I've rewritten the names of the variables here and this should work (not because of the name change, but because I've checked that they are consistent). Sorry for all the grief, Schneb; I didn't check this against a batch of files with comments because I don't have any and would have had to do a bunch.

If you don't say "where" as in Mark's script, the comment is just the first item in the list. I can't check that because I don't have photoshop.

Code:

set Fldr to choose folder
tell application "Finder"
        try
                set Pics to files of entire contents of Fldr as alias list -- digs down through enclosed folders
        on error -- only one file found in chosen folder; a bug for as alias list
                set Pics to files of entire contents of Fldr as alias as list -- deals with only one
        end try
        set tKinds to {"GIF document", "GIF Image", "JPEG document", "JPEG Image", "PNG document", "TIFF document", "TIFF Image", "Adobe Photoshop JPEG file"} -- should include your photos
        repeat with onePic in Pics -- iterate through the pics
                if kind of onePic is in tKinds then
                        set Cmt to comment of onePic -- get the comment from the Finder
                        tell application "GraphicConverter" to set file iptc of onePic to {Cmt} -- set it with GC
                end if
        end repeat
end tell


mark hunte 08-07-2007 09:37 AM

I have tested this and it works.
Code:

set F to choose folder
tell application "Finder"
        --try
        set P to (files of entire contents of F) -- digs down through enclosed folders
        --on error -- only one file found in chosen folder; a bug for as alias list
        --set P to files of entire contents of F -- deals with only one
        --end try
        set K to {"GIF document", "GIF Image", "JPEG document", "JPEG Image", "PNG document", "TIFF document", "TIFF Image", "Adobe Photoshop JPEG file"} -- should include your photos
        repeat with I from 1 to number of items in P -- iterate through the pics
                set this_item to item I of P as alias
                if kind of this_item is in K then
                        set C to («class ktxt» of ((comment of this_item as string) as record)) -- get the comment from the Finder
                       
                        log C
                        tell application "GraphicConverter" to set file iptc of this_item to {C} -- set it with GC
                end if
        end repeat
end tell


schneb 08-07-2007 12:19 PM

NovaScotian, you are brilliant. It indeed works! I tested it on a folder full of photos and it wrote all my Spotlight comments to the description IPTC, just like I wanted. Now if I ever lose my .DS_Store files, I will not pine because of the loss of Spotlight comments--it is now a part of the photo itself!

Thanks so much for your time on this.

Schneb

NovaScotian 08-07-2007 12:46 PM

More than welcome, Schneb; Sorry it took so long to debug it. :rolleyes:


All times are GMT -5. The time now is 01:06 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.