iView Script to add "people" entry

Started Oct 23, 2005 | Discussions
Duncan C Veteran Member • Posts: 7,674
iView Script to add "people" entry

I did a photo shoot last weekend where I took about 260 pictures of 50 or so different families. I decided to use iView's "people" annotation to track the name of each family. However, adding a "people" entry for a group of records is tedius: You have to select the records, go to the "people" tab, select "add new entry", type the name for the new "people" entry, then either drag your selected items onto the newly created "people" entry or click on the popup menu for the new entry and select "add selected media items.

I wanted to be able to select a group of files, click one key, enter a name, and press return.

I wrote an AppleScript that lets me do just that. If you enter the script below, save it to the "tools" folder inside iView, and then use System Preferences to add a keyboard shortcut to the new script, you can use one keystroke to invoke the script, type the name of your new group of people, and press return to assign that new value to the selected items.

First, here's the script:
-----
set theAnswer to ""

set theReply to display dialog "Enter 'people' for selected items:" default answer theAnswer buttons {"OK", "Cancel"} default button 1 giving up after 30
set theAnswer to text returned of theReply
if theAnswer is not "" then
tell application "iView MediaPro"
set selectedItems to the selection of catalog 1
set total_count to number of items in selectedItems
repeat with theItem in selectedItems

-- hide signature --

If you want to change another annotation, change the word "people" in the next 2 lines to
--the annotation you want to change
set oldPeople to people of annotations of theItem
set people of annotations of theItem to oldPeople & theAnswer
end repeat
end tell
end if
-----

You'll want to save this script to the "tools" folder of the iView Scripts folder. Here's how:

Open the script editor and paste in the script above.

Finally, save this script into the tools scripts folder inside MediaPro. That is a little tricky, since iView MediaPro is a "package". Here's what to do:

1. In the Script editor, save your newly edited script to the desktop. I call mine "Set people of sel.scpt" (short for set people field of selected items.)

2. Go to the finder and right click on the iViewMediaPro Appolication icon. In the pop-up menu, select "show contents" to open the application package.

3. Once you're inside the package, go to " contents/shared support/Plug-ins/scripts/tools." Now copy the script into the "tools" folder. Once you've copied your script into the tools folder, click on it, press return, and select "copy" from the edit menu to copy the filename into the clipboard.

4. Now we need to assign a keyboard shortcut to our new script. To do that, open System Preferences in the Apple menu, select "keyboard and mouse", and click on the "keyboard shortcuts" tab. Once there, scroll down to "Appliction Keyboard Shortcuts" and click on it. If there's not an entry for iView MediaPro, click the plus sign and click on the "application" popup in the resulting dialog. Now select "iView MediaPro" to add a shortcuts entry for iView. Now select iView under "Appliction Keyboard Shortcuts" and click the plus sign again, this time to add a new shortcut for iView MediaPro. You'll be prompted for a menu title. Paste in the name of the script you copied into the clipboard in step three. Then tab to the keyboard shortcut field and enter a keyboard shortcut for your new script. I used option p (for people). It's not taken by the default menu shortcuts, it makes sense, and it's easy to press with 2 fingers.

5. Quit MediaPro and restart it so that it loads your new script and rebuilds the menus.

Now, when you want to add a new "people" entry for a group of records, select the records and press your keyboard shortcut (option p if you used my suggestion.) Enter a new "people" entry for your selected items, press return, and they are added.

Note that this same script would work for adding other annotations like keyword, author, copyright, genre, etc. with very minor changes. You'd just have to replace the word "people" in the script with the annotation that you want to change.

--
dpreview and PBase supporter.

http://www.pbase.com/duncanc

Jaded Snapper Regular Member • Posts: 434
Re: iView Script to add "people" entry

That's excellent!! Thank you.

OP Duncan C Veteran Member • Posts: 7,674
Re: Minor changes to change genre, location

Jaded Snapper,

Glad to help.

In my previous posting, I said that this script could be used to set other annotation fields as well.

I realized that some of the annotations work differently than others.

For annotations like people and keywords, a given image can have more than one annotation (A picture can show more than one person, or have more than one keyword setting.) For others, a given image can only have one value for that annotation (e.g. a given image can only have one value for location, and belong to only one Genre.)

For annotations that only allow one value, you need to change the syntax of the statement that sets the annotation.

In the example script, I used the statement:

set people of annotations of theItem to oldPeople & theAnswer

to add a new "people" entry to the selected image

For genre or location, you want to change it so it doesn't add the new value ot the old. Instead, it should set the annotation to the value you give.

So, for genre, it would read like this:

set genre of annotations of theItem to theAnswer

Duncan C
---
dpreview and PBase supporter.

http://www.pbase.com/duncanc

Jaded Snapper Regular Member • Posts: 434
Re: Minor changes to change genre, location

I now have three scripts, for location, keyword and people.

I used Script Editor Find and replace to quickly change the words. Also - I put the scripts in Library/Application Support/iView/Plug-ins/Scripts, then they appear in the 'root' of the Scripts menu and also you don't need to open the iView package.

Thanks for the tip on the Location - I've just edited my script.

(I used alt l for location and alt k for keyword, to keep consistent)

Thank you again!!

Now all I need is a keystroke to lock/unlock files...

OP Duncan C Veteran Member • Posts: 7,674
~/Library/Application Support/iView is a much better place to store scripts!

Jaded Snapper wrote:

I now have three scripts, for location, keyword and people.

I used Script Editor Find and replace to quickly change the words.
Also - I put the scripts in Library/Application
Support/iView/Plug-ins/Scripts, then they appear in the 'root' of
the Scripts menu and also you don't need to open the iView package.

Jaded Snapper,

Putting the scripts in the Application Support folder is cool. I keep having to move my scripts each time I upgrade my version of iView, and now I won't have to, and I also won't have to worry about the package file. Plus, spotlight and find file don't find the script files in the iView package folder.

My system didn't have an iView folder inside " Library/Application Support". I had to create it. How did you know that iView would look for scripts there if you created one?

Thanks for the tip on the Location - I've just edited my script.

(I used alt l for location and alt k for keyword, to keep consistent)

Alt? What's this "alt" thing? Are you a former Windows user? Alt is a Windows term, not a Mac term. Apple didn't start putting the "alt" label on Mac keyboards until fairly recently.

Thank you again!!

Glad I could be of help.

Now all I need is a keystroke to lock/unlock files...

I could probably write a quick script to do that for you. Do you want it to work in iView, or in the Finder?

Duncan C

-- hide signature --

dpreview and PBase supporter.

http://www.pbase.com/duncanc

OP Duncan C Veteran Member • Posts: 7,674
iView doesn't see Tools and Selet subfolders from system Library folder.

Unfortunately, iView doesn't follow the same convention for scripts stored in library/Application Support/scripts that it does for the files store in the application package. Specifically, if you put scripts in sub-folders called Scripts and Tools, it doesn't put them into the scripts menu. They all have to be at the top level of the Scripts folder. That's a shame -- I rather liked the folder grouping iView uses.

Duncan C.
--
dpreview and PBase supporter.

http://www.pbase.com/duncanc

Adam Tow Regular Member • Posts: 325
Re: iView Script to add "people" entry

There's another way to accomplish this without writing a script.

1) Select the media items you want to annotate in iView
2) Click on the Info tab
3) Expand the Annotations section
4) Expand the People section

5) Enter each person in the image. iView will perform type-ahead if you've entered that person before
6) Press tab to continue adding new people

7) When you are done, click on checkmark icon OR in a blank space in the thumbnail view.

8) iView will ask you if you want to add the annotations to the selected images or just the currently selected image.

-adam

-- hide signature --

Adam Tow
Web: http://www.tow.com/
Tomorrow begins today.

OP Duncan C Veteran Member • Posts: 7,674
Re: iView Script to add "people" entry

Adam,

I'm trying to figure out your method, and have a few questions:

Adam Tow wrote:

There's another way to accomplish this without writing a script.

1) Select the media items you want to annotate in iView
2) Click on the Info tab
3) Expand the Annotations section
4) Expand the People section
5) Enter each person in the image. iView will perform type-ahead if
you've entered that person before

How do you enter the person names? Do you double-click on the "Double click to add new people" entry in the people section? That's the only way I could figure out

6) Press tab to continue adding new people
7) When you are done, click on checkmark icon OR in a blank space
in the thumbnail view.

What checkmark icon? Is it somewhere in the annotatlions list in the info column? Is it in the thumbnail view? I can't see a checkmark. I discovered that I CAN click somewhere outside of my selection (in a list view OR thumbnail view) and iView asks if I want to add the new annotation.

8) iView will ask you if you want to add the annotations to the
selected images or just the currently selected image.

I can get your method to work, excluding the confusion about check-boxes. However, unless I'm missing something it takes several more steps than my script. My goal for the script was to be able to add people (or keyword, etc) annotations with just a few keystrokes, and no clicking in different places. If you're adding a lot of entries, reducing the number of steps makes a big difference in the time it takes.

Duncan C

-adam

-- hide signature --

Adam Tow
Web: http://www.tow.com/
Tomorrow begins today.

-- hide signature --

dpreview and PBase supporter.

http://www.pbase.com/duncanc

Adam Tow Regular Member • Posts: 325
Re: iView Script to add

Duncan:

5) Enter each person in the image. iView will perform type-ahead if
you've entered that person before

How do you enter the person names? Do you double-click on the
"Double click to add new people" entry in the people section?

Yes

That's the only way I could figure out

6) Press tab to continue adding new people
7) When you are done, click on checkmark icon OR in a blank space
in the thumbnail view.

What checkmark icon? Is it somewhere in the annotatlions list in
the info column? Is it in the thumbnail view? I can't see a

The checkbox is a little icon right below the Info/Organize buttons at the top of the window. It's such a small target that I rarely use it, preferring instead to click somewhere in the thumbnail view.

I can get your method to work, excluding the confusion about
check-boxes. However, unless I'm missing something it takes several
more steps than my script. My goal for the script was to be able to
add people (or keyword, etc) annotations with just a few
keystrokes, and no clicking in different places. If you're adding a
lot of entries, reducing the number of steps makes a big difference
in the time it takes.

Yes, your script has a lot fewer steps, and is a good start. The type-ahead feature of iView is useful to reduce the amount of name typing one has to do when annotating large number of images.

I've taken the liberty of modifying your script to add the following features:

1) Multiple people support. The people annotation can take multiple items (like Keywords and Categories). Right now, your script appends new people to just one line. The script treats commas as a delimiter. So "Adam, John, Duncan" become three entries under the People section.

2) Duplicate item detection. The new script does not add a person if s/he is already in the list.

Here's the modified script below:

set theAnswer to ""

set theReply to display dialog "Enter 'people' for selected items:" default answer theAnswer buttons {"OK", "Cancel"} default button 1 giving up after 30
set theAnswer to text returned of theReply
if theAnswer is not "" then
tell application "iView MediaPro"

-- hide signature --

Separate people using comma as a delimiter
set AppleScript's text item delimiters to ","
set theItems to text items in theAnswer
set AppleScript's text item delimiters to ""

-- Strip any whitespace from each item
set thePeople to {}
repeat with aPerson in theItems
set cmd to "php -r 'echo trim(\"" & aPerson & "\");'"
set thePerson to (do shell script cmd)
set thePeople to {thePerson} & thePeople
end repeat

set selectedItems to the selection of catalog 1
set total_count to number of items in selectedItems
repeat with theItem in selectedItems
set newPeople to people of annotations of theItem

-- Remove duplicates
repeat with aPerson in thePeople
if newPeople does not contain aPerson then set end of newPeople to aPerson
end repeat
set people of annotations of theItem to newPeople

end repeat
end tell
end if

Let me know what you think of the changes.

-adam

Jaded Snapper Regular Member • Posts: 434
Re: ~/Library/Application Support/iView is a much better place to store scripts!

Alt? What's this "alt" thing? Are you a former Windows user? Alt is a Windows term, not a Mac term. Apple didn't start putting the "alt" label on Mac keyboards until fairly recently.

No - I've been using Mac since 1986. I do use Windows too. But as you point out, it is on the keyboards, I've been responsible for several switchers, and it is far easier to support them over the phone by using what is written on the keycaps, rather than what is in my head!! Tell them to hit the Option key and you get a long, silent pause....

The Lock/Unlock would be just for iView - I find Action : Set Finder Properties : Lock Status : Unlock/Lock to be particularly tortuous. A one keypress toggle of Lock Status would be great for those times when I want to trash files that are locked.

Adam Tow Regular Member • Posts: 325
Re: iView Script to add

One thing to note about the modified script I posted earlier tonight. It doesn't work if you have entered text with quotes -- double or single.

-adam

-- hide signature --

Adam Tow
Web: http://www.tow.com/
Tomorrow begins today.

Jaded Snapper Regular Member • Posts: 434
Re: iView Script to add

Actually I have found that I can't get the modified script to work for Location - that word doesn't come up green in the script editor....

OP Duncan C Veteran Member • Posts: 7,674
Re: iView Script to add

Adam,

The checkbox was hidden in plain sight, it seems.

Regarding type-ahead: I use my script to assign NEW people entries to selected groups of items. If I want to add groups to an existing people entry, I just drag them onto the entry in the people list.

As for your enhancements to the script. You're obviously a much more accomplished script writer than I am. You've shown me several tricks that will be useful. Thanks.

Some specific points and questions:

Why do you strip out spaces from the entries? I use spaces in some of my people entries, and find them helpful (e.g. first name last name) Do spaces do any harm?

Through testing, I've also found that if you use my script to enter a "people" entry that's already defined for some of your items, iView just ignores the duplicates. Thus, I didn't worry about rejecting duplicates.

I like your technique of using commas to specify more than one attribute value for a given person. I did have some entries where I used a comma as part of the people name; (last name first name format) I might use a different delimiter like semicolon or a pipe symbol (" ") in my version of the script.

Duncan C.
--
dpreview and PBase supporter.

http://www.pbase.com/duncanc

Adam Tow Regular Member • Posts: 325
Re: iView Script to add

Duncan:

Why do you strip out spaces from the entries? I use spaces in some
of my people entries, and find them helpful (e.g. first name last
name) Do spaces do any harm?

It's just spaces at the beginning and end of a string. For instance, "John, Ben, Cary" would be delimited as "John", " Ben", " Cary". The script removes the spaces at the beginning of Ben and Cary.

Through testing, I've also found that if you use my script to enter
a "people" entry that's already defined for some of your items,
iView just ignores the duplicates. Thus, I didn't worry about
rejecting duplicates.

That's interesting, cause I got the exact opposite result. iView was adding duplicate people to an image.

-adam

-- hide signature --

Adam Tow
Web: http://www.tow.com/
Tomorrow begins today.

OP Duncan C Veteran Member • Posts: 7,674
Re: iView Script to add

Adam Tow wrote:
Duncan:

Why do you strip out spaces from the entries? I use spaces in some
of my people entries, and find them helpful (e.g. first name last
name) Do spaces do any harm?

It's just spaces at the beginning and end of a string. For
instance, "John, Ben, Cary" would be delimited as "John", " Ben", "
Cary". The script removes the spaces at the beginning of Ben and
Cary.

Adam,

That makes sense. Your little bit of shell code only removes leading and trailing spaces, then? If I entered "John Smith, Dave, Joe" I'd get {"John Smith", "Dave", "Joe"} with your code?

If I add delimiter code to my script I'll need to get rid of white space like you do.

[snip]
That's interesting, cause I got the exact opposite result. iView
was adding duplicate people to an image.

Odd. How, exactly, do you get duplicate people?

I think I just answered my own question. I usually use the "Organize" panel, and in that panel, there's one and only one entry for each unique "people" entry. If I add the same entry more than once, I CAN see a "people" column to the list view.

It looks like you're right and iView does not prevent duplicates.

Duncan

-adam

-- hide signature --

Adam Tow
Web: http://www.tow.com/
Tomorrow begins today.

-- hide signature --

dpreview and PBase supporter.

http://www.pbase.com/duncanc

Adam Tow Regular Member • Posts: 325
Re: iView Script to add

Duncan:

That makes sense. Your little bit of shell code only removes
leading and trailing spaces, then? If I entered "John Smith, Dave,
Joe" I'd get {"John Smith", "Dave", "Joe"} with your code?

Yup

I think I just answered my own question. I usually use the
"Organize" panel, and in that panel, there's one and only one entry
for each unique "people" entry. If I add the same entry more than
once, I CAN see a "people" column to the list view.

iView doesn't let you enter duplicate entries in the Info panel when manually adding names to the People section, but your original script allowed for it.

BTW, thanks for writing the initial version of the script. Although I miss having auto-complete, your script does make annotating images quite a bit faster than before. Now, I just have to make sure I spell everyone's names correctly!

I'll see if I can modify the script to allow for quotation marks.

-adam

Keyboard shortcuts:
FForum MMy threads