I want to get a list of keywords from iView MediaPro (a photo catalogue) http://www.iview-multimedia.com/ and sort them alphabetically. I’ve bluffed my way through and have previously created couple of working scripts for iView but I’m a bit stuck here…
I found ASCII_Sort at http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.05.htm
and am trying to see if that’s what I need. Here’s what I have so far:
on run
set selectedItems to GetSelection()
-- process each item --
tell application "iView MediaPro"
repeat with theItem in selectedItems
set origPath to the path of theItem
-- get the list of keywords from iView --
set keywordList to keywords of theItem
set keywords to ASCII_Sort(keywordList)
end repeat
save catalog 1
end tell
end run
-- sub-routines below --
-- get the selected images (IDs) in an array ---
on GetSelection()
set selectedItems to {}
tell application "iView MediaPro"
if catalog 1 exists then set selectedItems to the selection of catalog 1
end tell
if number of items in selectedItems is 0 then
display dialog ¬
"You need to select at least one media item in the front catalog in order to use this script." buttons {"OK"} default button ¬
"OK" with icon note giving up after 10
error number -128
end if
return selectedItems
end GetSelection
-- ASCII_Sort sub-routine --
on ASCII_Sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end ASCII_Sort
When I run this I get an error “iView MediaPro got an error: Can’t continue ASCII_Sort.”
I can see in the event log I am getting the keywords
tell application "iView MediaPro"
exists catalog 1
true
get selection of catalog 1
{media item id 1 of window 1}
get path of media item id 1 of catalog 1
"MacOneHD:Users:davidgordon:Desktop:test:test1.jpg"
get keywords of media item id 1 of catalog 1
{"delta", "zulu", "foxtrot", "tango", "romeo"}
ASCII_Sort({"delta", "zulu", "foxtrot", "tango", "romeo"})
"iView MediaPro got an error: Can't continue ASCII_Sort."
What’s my problem? What does "iView MediaPro got an error: Can’t continue ASCII_Sort."really mean?
Thanks!
AppleScript: 2.1.1
Browser: Camino
Operating System: Mac OS X (10.4)
You need to change this line:
set keywords to ASCII_Sort(keywordList)
to this:
set keywords to my ASCII_Sort(keywordList)
Whenever you call a handler from inside of an application tell block, you need to use the term my to get outside of the tell block and back into the main script.
Give it a try and see how it works.
Thanks, I remember reading that earlier today now…
Okay so now iView complains that it can’t set keywords to my sorted list
get keywords of media item id 1 of catalog 1
{"Beta", "Alpha", "Delta", "Echo", "Charlie"}
set keywords to {"Alpha", "Beta", "Charlie", "Delta", "Echo"}
"iView MediaPro got an error: Can't set keywords to {\"Alpha\", \"Beta\", \"Charlie\", \"Delta\", \"Echo\"}."
For what its worth, the iView dictionary says of keyword
keywords (list of Unicode text) : list of keyword
and as far as I know I’m trying to add a comma separated list, no quotes, in other words I want
Alpha, Beta, Charlie, Delta, Echo
Which may or may not be my problem?
Thanks again!
david:
I don’t have iView, so I cannot test anything out, but the next thing I would try is changing one more thing on your line that calls the ASCII_Sort handler, based on the immediately previous line, where you actually extract the keywords:
set keywords of theItem to my ASCII_Sort(keywordList)
As far as the quotes go, that is standard AppleScript for a list of string values. When your list reads:
{"Beta", "Alpha", "Delta", "Echo", "Charlie"}
It really does mean:
{Beta, Alpha, Delta, Echo, Charlie}
The quotes just tell the script that they are strings, so don’t worry about that.
Yes, thank you that works now.
I guess I don’t know enough basic AS to know all the commands and what goes where.
I’m going to post the full working script here in the spirit of the site. But I have one more question…
Why do Ihave the line
set origPath to the path of theItem
which I see from the event log tells me the path to the original photo as catalogued by iView. For example
get path of media item id 10 of catalog 1
"MacOneHD:Users:davidgordon:Desktop:test:test5.jpg"
The script works without that line. I guess its there left over from another script I copied. I wonder if I can use its output to create a dialogue box showing the progress of the script? But maybe that’s running before I can walk…
(* This script sorts the keywords in selected iView MediaPro records into alphabetical order and saves the catalog. Don't forget to sync back to the original files if you want them in order in the IPTC keyword field too. This script doesn't do that! *)
on run
set selectedItems to GetSelection()
-- process each item --
tell application "iView MediaPro"
repeat with theItem in selectedItems
set origPath to the path of theItem -- this line may be redundant --
-- get the list of keywords from iView --
set keywordList to keywords of theItem
set keywords of theItem to my ASCII_Sort(keywordList)
end repeat
save catalog 1
end tell
end run
-- sub-routines below --
-- get the selected images (IDs) in an array ---
on GetSelection()
set selectedItems to {}
tell application "iView MediaPro"
if catalog 1 exists then set selectedItems to the selection of catalog 1
end tell
if number of items in selectedItems is 0 then
display dialog ¬
"You need to select at least one media item in the front catalog in order to use this script." buttons {"OK"} default button ¬
"OK" with icon note giving up after 10
error number -128
end if
return selectedItems
end GetSelection
-- ASCII_Sort sub-routine --
on ASCII_Sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end ASCII_Sort
Thanks for your help!
Glad to hear all is well, and yes, your suspicion about the origPath line is correct; it is never referred to again throughout the script. An easy way to test that is to simply use the Cmd-F function (like any word processor) inside of Script Editor and search for the variable. If it is nowhere to be found, you can confidently delete that line, since nothing else is using it.