Simple Address Book script help request

I want an AppleScript to enter a single value in the 'Note' field for each record/contact in a certain group.
I wrote this:
tell application "Address Book"
repeat with allcontacts in group "Health"
set NewNote to "doctor"
set value of note to NewNote
end repeat
end tell
It compiles and seems to run OK. But nothing happens. What am I doing wrong?
(I wish I knew AS better Thanks!)
G5 DP 2 GHz   Mac OS X (10.4.10)   No Haxies; permissions frequently repaired etc

Hi Mark you have the right idea, but you are slightly off..
The biggest problem is in your loop. Like I said you do have the right idea though. When your looping with x in y "Y" must actually be a list of things, so in your case you need to build a list of all the contacts in group "Health" first.
=================================================
tell application "Address Book"
set allContacts to every person in group "Health"
repeat with singleContact in allContacts
set singleContact's note to ((get singleContact's note) & return & "doctor" as string)
end repeat
end tell
=================================================
So as you can hopefully see first we build a list of the person entries contained in group "Health" then we step through that list.
Also in my example we are preserving the contents of what may already exist in the note field rather then overwriting it.
Hope that helps!

Similar Messages

  • I added a contact to my iphone 4s and when I did a sync manually it is not showing up on my MAC in address book - please help....I checked off sync all contacts in iTunes  - does it only work one way from computer to phone?

    I added a contact to my iphone 4s and when I did a sync manually it is not showing up on my MAC in address book - please help....I checked off sync all contacts in iTunes  - does it only work one way from computer to phone?

    Is it because the new itunes looks different.
    View > Show Sidebar
    Then it should work just the same as on your old computer.

  • Running 10.5.8  Virus is attacking my address book.  Help please.

    running 10.5.8   Virus is attacking my address book. help please.

    No it isn't!
    There are many forms of ‘Malware’ that can affect a computer system, of which ‘a virus’ is but one type, ‘trojans’ another. Using the strict definition of a computer virus, no viruses that can attack OS X have so far been detected 'in the wild', i.e. in anything other than laboratory conditions. The same is not true of other forms of malware, such as Trojans. Whilst it is a fairly safe bet that your Mac has NOT been infected by a virus, it may have another security-related problem, but more likely a technical problem unrelated to any malware threat.
    You may find this User Tip on Viruses, Trojan Detection and Removal, as well as general Internet Security and Privacy, useful:
    https://discussions.apple.com/docs/DOC-2435
    The User Tip (which you are welcome to print out and retain for future reference) seeks to offer guidance on the main security threats and how to avoid them.
    More useful information can also be found here:
    http://www.reedcorner.net/mmg/

  • Address book gone -  HELP!!

    Haven't used address book in two weeks or so. This morning I went looking for a contact. When I opened Address Book there was nothing there. Yikes!!
    I have a back up to idisk and another user name that has all my info. BUT, I am not good with computers and can't figure out how to rename, reboot, rewhatever to restore the info where I'm using it.
    Any repliy will be much appreciated,
    Sheila
    Mac Mini Dual   Mac OS X (10.4.7)  

    This happened to me just two days ago.
    Do you have Backup? If so, this is copied from Backup Help Viewer.
    Restoring backed-up files using an existing backup plan
    If a file you backed up (using Backup) becomes lost or damaged, you can use Backup to restore it. You can restore backed-up files to their original location or to an alternate location of your choice.
    IMPORTANT: If you are restoring items from your iTunes or iPhoto library, click one of the links below for instructions.
    To restore backed-up files to their original location:
    Select a backup plan in the Backup window and click Restore.
    Select a backup in the Previous Backups column.
    Select the items you want to restore and click Restore Selection.
    In the dialog that appears, choose whether to restore only files missing from their original locations or all the files in the backup.
    If you deleted files accidentally and want to restore only the missing files, select "Restore missing items."
    To replace existing files with the backed-up files, select "Replace existing items."
    To restore the files to another location, select "Restore to an alternate location" before you click Restore Selection, choose where you want the files, and click Open.
    Note: Some applications—such as Mail, Stickies, and Address Book—store all of their data as a group, like a deck of cards. When you restore an address book, for example, the whole book gets replaced. That means that contacts added after the backup won't appear in the restored file.
    If you don't, then you can open up Address Book and click on the File menu. Then go down to Import, and choose whichever method you have them stored by (probably V-cards). When you click on that, a window will open up that will let you navigate to your iDisk to find the cards to import.
    MacBook   Mac OS X (10.4.8)  

  • Duplicated Every Contact in My Address Book, Need Help Deleting

    I recently had to trade in my 8830 for a new one due to warranty issues.  I am synced up with my employer's enterprise server and all the contacts I have on that server were re-synced but for some reason, I have two of every contact in my address book now.  I had some issues when re-syncing to the server and ran the sync twice.  I'm pretty positive it has something to do with that.  I'm sure there is a file in the options menu that I can delete, but I need somebody to tell me where it is.  If something goes haywire and I end up deleting all my contacts on the server, I'd be screwed.  Any help? Thanks

    Bump!

  • Outlook 2010 Address Book Disabled - Help Needed

    A couple of weeks ago, I updated my device software and my BBDesktop software.  Subsequently, my Outlook Address book will not sync and the Desktop software shows it disabled.  Does anyone have any ideas on a fix?  If not, what is a good BB help number to call?

    Have a look at this suggested solution
    KB01451
    Blackberry Best Advice - Back-up weekly
    If I have helped you please check the "Kudos" star on the right >>>>

  • Can't add anyone to my address book - PLEASE HELP!!!

    Prior to my last upgrade of thunderbird, this function was working fine. Now I cannot add anyone to my address book, and the copy to address book feature does nothing. It's a real pain cause I have to type every single persons email into the address bar which is driving me nuts!!!
    It may be an overall setting with the computer, but I have tried every possible option and it doesn't seem to allow me to add anyone. When I do it manually the ok but won't allow me to click it?!?
    Please help...

    https://support.mozilla.org/en-US/questions/996474

  • Adding a contact to an address book, please help!

    hi,
    I'm trying to write new infomation to my file but i cant seem to get it to work.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import java.text.*;
    public class AddressBook extends JFrame implements ActionListener
         FlowLayout leftLayout;
         JFrame winNew;
    JTextField txtName, txtPhone, txtMobile, txtAddress;
    JButton btnImport, btnAdd, btnNext, btnPrevious, btnSave;
    JLabel lblTitle, lblName, lblPhone, lblMobile, lblAddress;
    JPanel pTitle, pName, pPhone, pMobile, pAddress, pButtons;
         ArrayList<String> Name = new ArrayList<String>();
         ArrayList<String> Phone = new ArrayList<String>();
         ArrayList<String> Mobile = new ArrayList<String>();
         ArrayList<String> Address = new ArrayList<String>();
         ArrayList<String> temp = new ArrayList<String>();
         int index = 0;
              public static void main(String[] args)
              new AddressBook();
         public AddressBook()
              final int WIDTH = 450;
              final int HEIGHT = 400;
              JFrame win = new JFrame("Address Book");
              win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              leftLayout = new FlowLayout(FlowLayout.LEFT);
              pTitle = new JPanel();
              pTitle.setLayout(new FlowLayout(FlowLayout.CENTER));
              lblTitle = new JLabel("Address Book");
              pTitle.add(lblTitle);
              win.add(pTitle);
              win.setLayout(new GridLayout(6,1));
              win.setSize(WIDTH, HEIGHT);
              win.setBackground(Color.BLUE);
              win.setResizable(false);
              win.setLocationRelativeTo(null);
              pName = new JPanel();
              pName.setLayout(leftLayout);
              lblName = new JLabel("Name: ");
              txtName = new JTextField(20);
              win.add(pName);
              pName.add(lblName);
              pName.add(txtName);
              pPhone = new JPanel();
              pPhone.setLayout(leftLayout);
              lblPhone = new JLabel("Phone: ");
              txtPhone = new JTextField(13);
              win.add(pPhone);
              pPhone.add(lblPhone);
              pPhone.add(txtPhone);
              pMobile = new JPanel();
              pMobile.setLayout(leftLayout);
              lblMobile = new JLabel("Mobile: ");
              txtMobile = new JTextField(14);
              win.add(pMobile);
              pMobile.add(lblMobile);
              pMobile.add(txtMobile);
              pAddress = new JPanel();
              pAddress.setLayout(leftLayout);
              lblAddress = new JLabel("Address: ");
              txtAddress = new JTextField(30);
              win.add(pAddress);
              pAddress.add(lblAddress);
              pAddress.add(txtAddress);
              pButtons = new JPanel();
              btnImport = new JButton("Import");
              pButtons.add(btnImport);
              btnImport.addActionListener(this);
              btnAdd = new JButton("Add");
              pButtons.add(btnAdd);
              btnAdd.addActionListener(this);
              btnPrevious = new JButton("Previous");
              pButtons.add(btnPrevious);
              //btnPrevious.addActionListener(this);
              btnNext = new JButton("Next");
              pButtons.add(btnNext);
              //btnNext.addActionListener(this);
              btnSave = new JButton("Save");
              pButtons.add(btnSave);
              btnSave.addActionListener(this);
              win.add(pButtons);
              win.setVisible(true);
         public void actionPerformed(ActionEvent e)
              if (e.getSource() == btnImport)
                   importContacts();
              if (e.getSource() == btnAdd)
                   clearScreen();
              if (e.getSource() == btnPrevious)
                   Previous();
              if (e.getSource() == btnSave)
         writetoFile();
              else if (e.getSource() == btnNext)
                   Next();
              public void importContacts()
              try
                   BufferedReader infoReader = new BufferedReader(new FileReader("../files/example.buab"));
                   int i = 0;
                   String loadContacts;
                   while ((loadContacts = infoReader.readLine()) !=null)
                        temp.add(loadContacts);
                        i++;
                   int a = 0;
                   int b = 0;
                   for (a = 0, b = 0; a < temp.size(); a++, b++)
                   if (b == 4)
                        b = 0;
                   if (b == 0)
                        Name.add(temp.get(a));
                   if (b == 1)
                        Phone.add(temp.get(a));
                   if (b == 2)
                        Mobile.add(temp.get(a));
                   if (b == 3)
                        Address.add(temp.get(a));
              catch (IOException ioe)
              ioe.printStackTrace();
              txtName.setText(Name.get(0));
              txtPhone.setText(Phone.get(0));
              txtMobile.setText(Mobile.get(0));
              txtAddress.setText(Address.get(0));
              public void Previous()
                   if (index > 0)
                        index--;
                   importContacts();
              public void Next()
                   if(index < temp.size() - 1)
                   index++;
                   importContacts();
              public void clearScreen()
                   txtName.setText("");
                   txtPhone.setText("");
                   txtMobile.setText("");
                   txtAddress.setText("");
              public void writetoFile()
    PrintStream out = new PrintStream("../files/example.buab");
    for
    (int index = 0; index < Name.size(); index++)
    (int index = 0; index < Phone.size(); index++)
    (int index = 0; index < Mobile.size(); index++)
    (int index = 0; index < Address.size(); index++)
    out.println("");
    out.println("");
    out.println(Name.get(index));
    out.println(Phone.get(index));
    out.println(Mobile.get(index));
    out.println(Address.get(index));
    i get an ioexception, must catch or throw, i tried to add catch but it says i must have try, so i added try and it says i cant have catch without try! what am I doing wrong??
    am i doing it right also? should this be in my options? i.e if i press save button?
    also why isn't my next and previous buttons working??
    and one more thing, is there an easier way to show the contents of my file to the jtextfields? (import contacts class)
    thanks

    sorry i did try to do this but didnt see the code bit.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import java.text.*;
    public class AddressBook extends JFrame implements ActionListener
         FlowLayout leftLayout;
         JFrame winNew;
            JTextField txtName, txtPhone, txtMobile, txtAddress;
            JButton btnImport, btnAdd, btnNext, btnPrevious, btnSave;
            JLabel lblTitle, lblName, lblPhone, lblMobile, lblAddress;
            JPanel pTitle, pName, pPhone, pMobile, pAddress, pButtons;
             ArrayList<String> Name = new ArrayList<String>();
             ArrayList<String> Phone = new ArrayList<String>();
             ArrayList<String> Mobile = new ArrayList<String>();
             ArrayList<String> Address = new ArrayList<String>();
             ArrayList<String> temp = new ArrayList<String>();
             int index = 0;
                  public static void main(String[] args)
                      new AddressBook();
                public AddressBook()
              final int WIDTH = 450;
              final int HEIGHT = 400;
              JFrame win = new JFrame("Address Book");
              win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              leftLayout = new FlowLayout(FlowLayout.LEFT);
              pTitle = new JPanel();
              pTitle.setLayout(new FlowLayout(FlowLayout.CENTER));
              lblTitle = new JLabel("Address Book");
              pTitle.add(lblTitle);
              win.add(pTitle);
              win.setLayout(new GridLayout(6,1));
              win.setSize(WIDTH, HEIGHT);
              win.setBackground(Color.BLUE);
              win.setResizable(false);
              win.setLocationRelativeTo(null);
              pName = new JPanel();
              pName.setLayout(leftLayout);
              lblName = new JLabel("Name: ");
              txtName = new JTextField(20);
              win.add(pName);
              pName.add(lblName);
              pName.add(txtName);
              pPhone = new JPanel();
              pPhone.setLayout(leftLayout);
              lblPhone = new JLabel("Phone: ");
              txtPhone = new JTextField(13);
              win.add(pPhone);
              pPhone.add(lblPhone);
              pPhone.add(txtPhone);
              pMobile = new JPanel();
              pMobile.setLayout(leftLayout);
              lblMobile = new JLabel("Mobile: ");
              txtMobile = new JTextField(14);
              win.add(pMobile);
              pMobile.add(lblMobile);
              pMobile.add(txtMobile);
              pAddress = new JPanel();
              pAddress.setLayout(leftLayout);
              lblAddress = new JLabel("Address: ");
              txtAddress = new JTextField(30);
              win.add(pAddress);
              pAddress.add(lblAddress);
              pAddress.add(txtAddress);
              pButtons = new JPanel();
              btnImport = new JButton("Import");
              pButtons.add(btnImport);
              btnImport.addActionListener(this);
              btnAdd = new JButton("Add");
              pButtons.add(btnAdd);
              btnAdd.addActionListener(this);
              btnPrevious = new JButton("Previous");
              pButtons.add(btnPrevious);
              //btnPrevious.addActionListener(this);
              btnNext = new JButton("Next");
              pButtons.add(btnNext);
              //btnNext.addActionListener(this);
              btnSave = new JButton("Save");
              pButtons.add(btnSave);
              btnSave.addActionListener(this);
              win.add(pButtons);
              win.setVisible(true);
             public void actionPerformed(ActionEvent e)
                      if (e.getSource() == btnImport)
                           importContacts();
                      if (e.getSource() == btnAdd)
                           clearScreen();
                          if (e.getSource() == btnPrevious)
                           Previous();   
                          if (e.getSource() == btnSave)
                         writetoFile();
                         else if (e.getSource() == btnNext)
                           Next();
                  public void importContacts()
                      try
                               BufferedReader infoReader = new BufferedReader(new FileReader("../files/example.buab"));
                               int i = 0;
                               String loadContacts;
                               while ((loadContacts = infoReader.readLine()) !=null)
                                        temp.add(loadContacts);
                                        i++;
                               int a = 0;
                               int b = 0;
                               for (a = 0, b = 0; a < temp.size(); a++, b++)
                                   if (b == 4)
                                            b = 0;
                                   if (b == 0)
                                            Name.add(temp.get(a));   
                                   if (b == 1)
                                            Phone.add(temp.get(a));   
                                   if (b == 2)
                                            Mobile.add(temp.get(a));   
                                   if (b == 3)
                                            Address.add(temp.get(a));   
                          catch (IOException ioe)
                              ioe.printStackTrace();
                      txtName.setText(Name.get(0));
                      txtPhone.setText(Phone.get(0));
                      txtMobile.setText(Mobile.get(0));
                      txtAddress.setText(Address.get(0));
              public void Previous()
                   if (index > 0)
                        index--;
                   importContacts();
              public void Next()
                   if(index < temp.size() - 1)
                   index++;
                   importContacts();
              public void clearScreen()
                   txtName.setText("");
                   txtPhone.setText("");
                   txtMobile.setText("");
                   txtAddress.setText("");
              public void writetoFile()
                           PrintStream out = new PrintStream("../files/example.buab");
                            for
                            (int index = 0; index < Name.size(); index++)
                            (int index = 0; index < Phone.size(); index++)
                            (int index = 0; index < Mobile.size(); index++)
                            (int index = 0; index < Address.size(); index++)
                                   out.println("");
                                   out.println("");
                                   out.println(Name.get(index));
                                   out.println(Phone.get(index));
                                   out.println(Mobile.get(index));
                                   out.println(Address.get(index));
                            out.close();
    }

  • I just purchased a new to me ibook g4 I have all the disks but the cd does not seem to read them properly. I wanted to re install everythMost everything works anyway except my address book application , help how do I reinstall

    I just purchased a new to me ibook g4. I have all the disks but they do not seem to work properly. When I restart holding the C key they just spit out of the drive. I wanted to reset everything back to factory and start over but no go. Most everything works anyway except my address book application. It seems to be missing. How can I download and reinstall a new address book App. Thanks, John

    iBook G4/1.33 12-Inch (Mid-2005 - Op)
    1.33 GHz PowerPC 7447a (G4)
    Intro Date:
    July 26, 2005
    Disc Date:
    May 16, 2006
    Order No:
    M9846LL/A
    Model No:
    A1133 (EMC N/A)
    Subfamily:
    iBook G4 - Mid-2005
    Model ID:
    PowerBook6,7
    Std. RAM:
    512 MB
    Std. VRAM:
    32 MB
    Std. HD:
    40 GB (4200 RPM)
    Std. Optical:
    8X "Combo Drive"
    Complete iBook G4/1.33 12-Inch (Mid-2005 - Op) Specs
    The problem with accessing the content of the disks is the CD Drive does not seem to access them. It also has a heck of a time ejecting them. Other disks seem to read. The unit came with imovie disks and I can use them. The disks look perfectly good no scratches but they just don't work, I was hoping I could just get a online copy of the address book to replace the one that seems to be missing. Or find it somewhere on my drive. Have no clue where to look though. 

  • Hi all, i want a software for mac which can view conntact card in address book. please help me.., Hi all, i want a software for mac which can view conntact card in address book. please help me..

    HI ALL,
    I HAVE TWO MACBOOK AND ONE WINDOWS SYSTEM. I WANT TO SHARE THE CONTACTS OF WINDOWS 7 TO MACBOOKS. ALSO I WANT TO SEE THE SCANNED CONTACT CARDS IN MY ADDRESS BOOK. PLEASE GIVE ME A SOLUTION FOR THIS.

    iCloud: Troubleshooting iCloud Contacts
    Yahoo won't sync with iCloud and isn't supposed to.

  • Simple Address Book AppleScript (substitution) question

    I want an AppleScript to enter a single value in the 'Note' field for each record/contact in a certain group.
    I wrote this:
    tell application "Address Book"
    repeat with allcontacts in group "Health"
    set NewNote to "doctor"
    set value of note to NewNote
    end repeat
    end tell
    It compiles and seems to run OK. But nothing happens. What am I doing wrong?
    (I wish I knew AS better Thanks!)
    G5 DP 2 GHz   Mac OS X (10.4.10)   No Haxies; permissions frequently repaired etc

    answer supplied in AS forum.

  • I have a quick filter but cannot dispay all incoming emails, only those from my address book. Help

    I was trying to add a junk filter. Now I have a quick filter with options for unread, starred, only messages from address book, tags, attachments.
    If I turn the quick filter off, I only get unread messages.
    If I turn the quick filter on, I can get all messages from my address book (read and unread) but no mail from others.
    I want all incoming email displayed I have no option to do this. What should I do???

    Are you saying nothing changes if you toggle the buttons in the QuickFilter for Unread, Contacts etc?

  • Simple focus magic script help please

    Dipping my toes for the first time - more code to learn - brain hurting.
    I've recorded a very simple script to run a basic sharpening step in focus magic before creating web galleries.   It works except it asks for a decision in focus magic which is a pain running 40-70 pictures through (200 in show jump season).
    the desired aim is each photo to be "out of focus" sharpening at 1 pixel @ 100% and what I have is as follows.  I think there may be a yes/no return step I want rid of and I'm hoping sorting this out will be a good first step in learning.  Thanks for any help
    REM =======================================================
    DIM objApp
    SET objApp = CreateObject("Photoshop.Application")
    REM Use dialog mode 3 for show no dialogs
    DIM dialogMode
    dialogMode = 3
    DIM idOpn
    idOpn = objApp.CharIDToTypeID( "Opn " )
        DIM desc1
        SET desc1 = CreateObject( "Photoshop.ActionDescriptor" )
        DIM idnull
        idnull = objApp.CharIDToTypeID( "null" )
        Call desc1.PutPath( idnull, "C:\\APRESSbox\\ExRaw2process\\0812GlensEX\\MagstoGO\\0812GlentoranWEB\\WK08008DS Glentoran.JPG" )
    Call objApp.ExecuteAction( idOpn, desc1, dialogMode )
    REM =======================================================
    DIM objApp
    SET objApp = CreateObject("Photoshop.Application")
    REM Use dialog mode 3 for show no dialogs
    DIM dialogMode
    dialogMode = 3
    DIM idFltr
    idFltr = objApp.CharIDToTypeID( "Fltr" )
        DIM desc2
        SET desc2 = CreateObject( "Photoshop.ActionDescriptor" )
        DIM idUsng
        idUsng = objApp.CharIDToTypeID( "Usng" )
        Call desc2.PutString( idUsng, "Fix Out-of-focus Blur" )
    Call objApp.ExecuteAction( idFltr, desc2, dialogMode )
    REM =======================================================
    DIM objApp
    SET objApp = CreateObject("Photoshop.Application")
    REM Use dialog mode 3 for show no dialogs
    DIM dialogMode
    dialogMode = 3
    DIM idCls
    idCls = objApp.CharIDToTypeID( "Cls " )
        DIM desc3
        SET desc3 = CreateObject( "Photoshop.ActionDescriptor" )
        DIM idSvng
        idSvng = objApp.CharIDToTypeID( "Svng" )
        DIM idYsN
        idYsN = objApp.CharIDToTypeID( "YsN " )
        DIM idN
        idN = objApp.CharIDToTypeID( "N   " )
        Call desc3.PutEnumerated( idSvng, idYsN, idN )
    Call objApp.ExecuteAction( idCls, desc3, dialogMode )

    The open and close steps you should be able to do using the DOM and not have to use scriptlistener.
    For the filter You might want to see if it can be recorded and played back as an action. If so then just calling that action would be an easy way to run the filter. If it can be recorded you may be able ( at least with javascript ) to make the executeAction call with dialogMode set to all and assign the results to a variable. That variable with contain an Action Descriptor. With most filters the setting you used in the filter dialog will be in that descriptor. You just need to pull the descriptor apart to find what the setting are. Or( again using javascript ) xtools has a script that will convert an action into javascript. It is mostly action manager( scriptlistener ) so you should be able to translate the output to VBS.

  • Saveas Scripting help request

    I am trying to piece together a maro that will initially resize an image and save it with a different suffix at different size increments. I found within the cs5 scripts folder the macro 'Fit Image.jsx' that would allow me to resize correctly but am lost on how to add in the subsequent save steps and additional resize and saves. I would like to have it save the image with 5 different file sizes and suffixes (400x400 '-2' suffix, 250x250 '-2T', 150x150 '-1', 100x100 '-0', and 50x50 '-2S'). I found some information on the saveas http://forums.adobe.com/message/2652204 but have no experience with javascript. I have some understanding of VBA and believe a loop could be used but haven't the slightest idea how to set this up. Is there anyone out there that could help walk me through this and lend me a hand?
    ---Below contains the 'Fit Image.jsx' file that I found---
    // c2008 Adobe Systems, Inc. All rights reserved.
    // Written by Ed Rose
    // based on the ADM Fit Image by Charles A. McBrian from 1997
    // edited by Mike Hale added option to avoid resize on images already smaller than target size
    @@@BUILDINFO@@@ Fit Image.jsx 1.0.0.21
    /* Special properties for a JavaScript to enable it to behave like an automation plug-in, the variable name must be exactly
       as the following example and the variables must be defined in the top 1000 characters of the file
    // BEGIN__HARVEST_EXCEPTION_ZSTRING
    <javascriptresource>
    <name>$$$/JavaScripts/FitImage/Name=Fit Image...</name>
    <menu>automate</menu>
    <enableinfo>true</enableinfo>
    <eventid>3caa3434-cb67-11d1-bc43-0060b0a13dc4</eventid>
    <terminology><![CDATA[<< /Version 1
                             /Events <<
                              /3caa3434-cb67-11d1-bc43-0060b0a13dc4 [($$$/AdobePlugin/FitImage/Name=Fit Image) /imageReference <<
                               /width [($$$/AdobePlugin/FitImage/Width=width) /pixelsUnit]
                               /height [($$$/AdobePlugin/FitImage/Height=height) /pixelsUnit]
                               /limit [($$$/AdobePlugin/FitImage/limit=Don't Enlarge) /boolean]
                              >>]
                             >>
                          >> ]]></terminology>
    </javascriptresource>
    // END__HARVEST_EXCEPTION_ZSTRING
    // enable double clicking from the Macintosh Finder or the Windows Explorer
    #target photoshop
    // debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
    // $.level = 2;
    // debugger; // launch debugger on next line
    // on localized builds we pull the $$$/Strings from a .dat file, see documentation for more details
    $.localize = true;
    var isCancelled = true; // assume cancelled until actual resize occurs
    // the main routine
    // the FitImage object does most of the work
    try {
        // create our default params
        var sizeInfo = new SizeInfo();
        GlobalVariables();
        CheckVersion();
        var gIP = new FitImage();
        if ( DialogModes.ALL == app.playbackDisplayDialogs ) {
            gIP.CreateDialog();
            gIP.RunDialog();
        else {
            gIP.InitVariables();
            ResizeTheImage(sizeInfo.width.value, sizeInfo.height.value);
        if (!isCancelled) {
            SaveOffParameters(sizeInfo);
    // Lot's of things can go wrong
    // Give a generic alert and see if they want the details
    catch( e ) {
        if ( DialogModes.NO != app.playbackDisplayDialogs ) {
            alert( e + " : " + e.line );
    // restore the dialog modes
    app.displayDialogs = gSaveDialogMode;
    isCancelled ? 'cancel' : undefined;
    function ResizeTheImage(width, height) {
        var oldPref = app.preferences.rulerUnits;
        var docWidth;
        var docHeight;
        var docRatio;
        var newWidth;
        var newHeight;
        var resolution = app.activeDocument.resolution;
        var limit = sizeInfo.limit;
        app.preferences.rulerUnits = Units.PIXELS; // save old preferences
        // original width, height
        docWidth = (1.0 * app.activeDocument.width * resolution) / 72.0; // decimal inches assuming 72 dpi (used in docRatio)
        docHeight = (1.0 * app.activeDocument.height * resolution) / 72.0; // ditto
        if (docWidth < 1.0 || docHeight < 1.0)
            return true; // error
        if (width < 1 || height < 1)
            return true; // error
        if ( limit && ( docWidth <= width && docHeight <= height ) ){
            app.preferences.rulerUnits = oldPref; // restore old prefs
            isCancelled = false; // if get here, definitely executed
            return false; // no error
        docRatio = docWidth / docHeight; // decimal ratio of original width/height
        newWidth = width;
        newHeight = ((1.0 * width) / docRatio); // decimal calc
        if (newHeight > height) {
            newWidth = docRatio * height; // decimal calc
            newHeight = height;
        // resize the image using a good conversion method while keeping the pixel resolution
        // and the aspect ratio the same
        app.activeDocument.resizeImage(newWidth, newHeight, resolution, ResampleMethod.BICUBIC);
        app.preferences.rulerUnits = oldPref; // restore old prefs
        isCancelled = false; // if get here, definitely executed
        return false; // no error
    // created in
    function SaveOffParameters(sizeInfo) {
        // save off our last run parameters
        var d = objectToDescriptor(sizeInfo, strMessage);
        app.putCustomOptions("3caa3434-cb67-11d1-bc43-0060b0a13dc4", d);
        app.playbackDisplayDialogs = DialogModes.ALL;
        // save off another copy so Photoshop can track them corectly
        var dd = objectToDescriptor(sizeInfo, strMessage);
        app.playbackParameters = dd;
    function GlobalVariables() {
        // a version for possible expansion issues
        gVersion = 1.1;
        gMaxResize = 300000;
        // remember the dialog modes
        gSaveDialogMode = app.displayDialogs;
        app.displayDialogs = DialogModes.NO;
        gInAlert = false;
        // all the strings that need to be localized
        strTitle = localize( "$$$/JavaScript/FitImage/Title=Fit Image" );
        strConstrainWithin = localize( "$$$/JavaScript/FitImage/ConstrainWithin=Constrain Within" );
        strTextWidth = localize("$$$/JavaScripts/FitImage/Width=&Width:");
        strTextHeight = localize("$$$/JavaScripts/FitImage/Height=&Height:");
        strTextPixels = localize("$$$/JavaScripts/FitImage/Pixels=pixels");
        strButtonOK = localize("$$$/JavaScripts/FitImage/OK=OK");
        strButtonCancel = localize("$$$/JavaScripts/FitImage/Cancel=Cancel");
        strTextSorry = localize("$$$/JavaScripts/FitImage/Sorry=Sorry, Dialog failed");
        strTextInvalidType = localize("$$$/JavaScripts/FitImage/InvalidType=Invalid numeric value");
        strTextInvalidNum = localize("$$$/JavaScripts/FitImage/InvalidNum=A number between 1 and 300000 is required. Closest value inserted.");
        strTextNeedFile = localize("$$$/JavaScripts/FitImage/NeedFile=You must have a file selected before using Fit Image");
        strMessage = localize("$$$/JavaScripts/FitImage/Message=Fit Image action settings");
        strMustUse = localize( "$$$/JavaScripts/ImageProcessor/MustUse=You must use Photoshop CS 2 or later to run this script!" );
        strLimitResize = localize("$$$/JavaScripts/FitImage/Limit=Don^}t Enlarge");
    // the main class
    function FitImage() {
        this.CreateDialog = function() {
            // I will keep most of the important dialog items at the same level
            // and use auto layout
            // use overriding group so OK/Cancel buttons placed to right of panel
            var res =
                "dialog { \
                    pAndB: Group { orientation: 'row', \
                        info: Panel { orientation: 'column', borderStyle: 'sunken', \
                            text: '" + strConstrainWithin +"', \
                            w: Group { orientation: 'row', alignment: 'right',\
                                s: StaticText { text:'" + strTextWidth +"' }, \
                                e: EditText { preferredSize: [70, 20] }, \
                                p: StaticText { text:'" + strTextPixels + "'} \
                            h: Group { orientation: 'row', alignment: 'right', \
                                s: StaticText { text:'" + strTextHeight + "' }, \
                                e: EditText { preferredSize: [70, 20] }, \
                                p: StaticText { text:'" + strTextPixels + "'} \
                            l: Group { orientation: 'row', alignment: 'left', \
                                    c:Checkbox { text: '" + strLimitResize + "', value: false }, \
                        buttons: Group { orientation: 'column', alignment: 'top',  \
                            okBtn: Button { text:'" + strButtonOK +"', properties:{name:'ok'} }, \
                            cancelBtn: Button { text:'" + strButtonCancel + "', properties:{name:'cancel'} } \
            // the following, when placed after e: in w and h doesn't show up
            // this seems to be OK since px is put inside the dialog box
            //p: StaticText { text:'" + strTextPixels + "'}
            // create the main dialog window, this holds all our data
            this.dlgMain = new Window(res,strTitle);
            // create a shortcut for easier typing
            var d = this.dlgMain;
            // match our dialog background color to the host application
            d.graphics.backgroundColor = d.graphics.newBrush (d.graphics.BrushType.THEME_COLOR, "appDialogBackground");
            d.defaultElement = d.pAndB.buttons.okBtn;
            d.cancelElement = d.pAndB.buttons.cancelBtn;
        } // end of CreateDialog
        // initialize variables of dialog
        this.InitVariables = function() {
            var oldPref = app.preferences.rulerUnits;
            app.preferences.rulerUnits = Units.PIXELS;
            // look for last used params via Photoshop registry, getCustomOptions will throw if none exist
            try {
                var desc = app.getCustomOptions("3caa3434-cb67-11d1-bc43-0060b0a13dc4");
                descriptorToObject(sizeInfo, desc, strMessage);
            catch(e) {
                // it's ok if we don't have any options, continue with defaults
            // see if I am getting descriptor parameters
            var fromAction = !!app.playbackParameters.count;
            if( fromAction ){
                // reset sizeInfo to defaults
                SizeInfo = new SizeInfo();
                // set the playback options to sizeInfo
                descriptorToObject(sizeInfo, app.playbackParameters, strMessage);
            // make sure got parameters before this
            if (app.documents.length <= 0) // count of documents viewed
                if ( DialogModes.NO != app.playbackDisplayDialogs ) {
                    alert(strTextNeedFile); // only put up dialog if permitted
                app.preferences.rulerUnits = oldPref;
                return false; // if no docs, always return
            var w = app.activeDocument.width;
            var h = app.activeDocument.height;
            var l = true;
            if (sizeInfo.width.value == 0) {
                sizeInfo.width = w;
            else {
                w = sizeInfo.width;
            if (sizeInfo.height.value == 0) {
                sizeInfo.height = h;
            else {
                h = sizeInfo.height;
            app.preferences.rulerUnits = oldPref;
            if ( DialogModes.ALL == app.playbackDisplayDialogs ) {
                var d = this.dlgMain;
                d.ip = this;
                d.pAndB.info.w.e.text = Number(w);
                d.pAndB.info.h.e.text = Number(h);
                d.pAndB.info.l.c.value = sizeInfo.limit;
            return true;
        // routine for running the dialog and it's interactions
        this.RunDialog = function () {
            var d = this.dlgMain;
            // in case hit cancel button, don't close
            d.pAndB.buttons.cancelBtn.onClick = function() {
                var dToCancel = FindDialog( this );
                dToCancel.close( false );
            // nothing for now
            d.onShow = function() {
            // do not allow anything except for numbers 0-9
            d.pAndB.info.w.e.addEventListener ('keydown', NumericEditKeyboardHandler);
            // do not allow anything except for numbers 0-9
            d.pAndB.info.h.e.addEventListener ('keydown', NumericEditKeyboardHandler);
            // hit OK, do resize
            d.pAndB.buttons.okBtn.onClick = function () {
                if (gInAlert == true) {
                    gInAlert = false;
                    return;
                var wText = d.pAndB.info.w.e.text;
                var hText = d.pAndB.info.h.e.text;
                var lValue = d.pAndB.info.l.c.value;
                var w = Number(wText);
                var h = Number(hText);
                sizeInfo.limit = Boolean(lValue);
                var inputErr = false;
                if ( isNaN( w ) || isNaN( h ) ) {
                    if ( DialogModes.NO != app.playbackDisplayDialogs ) {
                        alert( strTextInvalidType );
                    if (isNaN( w )) {
                        sizeInfo.width = new UnitValue( 1, "px" );
                        d.pAndB.info.w.e.text = 1;
                    } else {
                        sizeInfo.height = new UnitValue( 1, "px" );
                        d.pAndB.info.h.e.text = 1;
                        return false;
                else if (w < 1 || w > gMaxResize || h < 1 || h > gMaxResize) {
                    if ( DialogModes.NO != app.playbackDisplayDialogs ) {
                        gInAlert = true;
                        alert( strTextInvalidNum );
                if ( w < 1) {
                    inputErr = true;
                    sizeInfo.width = new UnitValue( 1, "px" );
                    d.pAndB.info.w.e.text = 1;
                if ( w > gMaxResize) {
                    inputErr = true;
                    sizeInfo.width = new UnitValue( gMaxResize, "px" );
                    d.pAndB.info.w.e.text = gMaxResize;
                if ( h < 1) {
                    inputErr = true;
                    sizeInfo.height = new UnitValue( 1, "px" );
                    d.pAndB.info.h.e.text = 1;
                if ( h > gMaxResize) {
                    inputErr = true;
                    sizeInfo.height = new UnitValue( gMaxResize, "px" );
                    d.pAndB.info.h.e.text = gMaxResize;
                if (inputErr == false)  {
                    sizeInfo.width = new UnitValue( w, "px" );
                    sizeInfo.height = new UnitValue( h, "px" );
                    if (ResizeTheImage(w, h)) { // the whole point
                        // error, input or output size too small
                    d.close(true);
                return;
            if (!this.InitVariables())
                return true; // handled it
            // give the hosting app the focus before showing the dialog
            app.bringToFront();
            this.dlgMain.center();
            return d.show();
    function CheckVersion() {
        var numberArray = version.split(".");
        if ( numberArray[0] < 9 ) {
            if ( DialogModes.NO != app.playbackDisplayDialogs ) {
                alert( strMustUse );
            throw( strMustUse );
    function FindDialog( inItem ) {
        var w = inItem;
        while ( 'dialog' != w.type ) {
            if ( undefined == w.parent ) {
                w = null;
                break;
            w = w.parent;
        return w;
    // Function: objectToDescriptor
    // Usage: create an ActionDescriptor from a JavaScript Object
    // Input: JavaScript Object (o)
    //        object unique string (s)
    //        Pre process converter (f)
    // Return: ActionDescriptor
    // NOTE: Only boolean, string, number and UnitValue are supported, use a pre processor
    //       to convert (f) other types to one of these forms.
    // REUSE: This routine is used in other scripts. Please update those if you
    //        modify. I am not using include or eval statements as I want these
    //        scripts self contained.
    function objectToDescriptor (o, s, f) {
        if (undefined != f) {
            o = f(o);
        var d = new ActionDescriptor;
        var l = o.reflect.properties.length;
        d.putString( app.charIDToTypeID( 'Msge' ), s );
        for (var i = 0; i < l; i++ ) {
            var k = o.reflect.properties[i].toString();
            if (k == "__proto__" || k == "__count__" || k == "__class__" || k == "reflect")
                continue;
            var v = o[ k ];
            k = app.stringIDToTypeID(k);
            switch ( typeof(v) ) {
                case "boolean":
                    d.putBoolean(k, v);
                    break;
                case "string":
                    d.putString(k, v);
                    break;
                case "number":
                    d.putDouble(k, v);
                    break;
                default:
                    if ( v instanceof UnitValue ) {
                        var uc = new Object;
                        uc["px"] = charIDToTypeID("#Pxl"); // pixelsUnit
                        uc["%"] = charIDToTypeID("#Prc"); // unitPercent
                        d.putUnitDouble(k, uc[v.type], v.value);
                    } else {
                        throw( new Error("Unsupported type in objectToDescriptor " + typeof(v) ) );
        return d;
    // Function: descriptorToObject
    // Usage: update a JavaScript Object from an ActionDescriptor
    // Input: JavaScript Object (o), current object to update (output)
    //        Photoshop ActionDescriptor (d), descriptor to pull new params for object from
    //        object unique string (s)
    //        JavaScript Function (f), post process converter utility to convert
    // Return: Nothing, update is applied to passed in JavaScript Object (o)
    // NOTE: Only boolean, string, number and UnitValue are supported, use a post processor
    //       to convert (f) other types to one of these forms.
    // REUSE: This routine is used in other scripts. Please update those if you
    //        modify. I am not using include or eval statements as I want these
    //        scripts self contained.
    function descriptorToObject (o, d, s, f) {
        var l = d.count;
        if (l) {
            var keyMessage = app.charIDToTypeID( 'Msge' );
            if ( d.hasKey(keyMessage) && ( s != d.getString(keyMessage) )) return;
        for (var i = 0; i < l; i++ ) {
            var k = d.getKey(i); // i + 1 ?
            var t = d.getType(k);
            strk = app.typeIDToStringID(k);
            switch (t) {
                case DescValueType.BOOLEANTYPE:
                    o[strk] = d.getBoolean(k);
                    break;
                case DescValueType.STRINGTYPE:
                    o[strk] = d.getString(k);
                    break;
                case DescValueType.DOUBLETYPE:
                    o[strk] = d.getDouble(k);
                    break;
                case DescValueType.UNITDOUBLE:
                    var uc = new Object;
                    uc[charIDToTypeID("#Rlt")] = "px"; // unitDistance
                    uc[charIDToTypeID("#Prc")] = "%"; // unitPercent
                    uc[charIDToTypeID("#Pxl")] = "px"; // unitPixels
                    var ut = d.getUnitDoubleType(k);
                    var uv = d.getUnitDoubleValue(k);
                    o[strk] = new UnitValue( uv, uc[ut] );
                    break;
                case DescValueType.INTEGERTYPE:
                case DescValueType.ALIASTYPE:
                case DescValueType.CLASSTYPE:
                case DescValueType.ENUMERATEDTYPE:
                case DescValueType.LISTTYPE:
                case DescValueType.OBJECTTYPE:
                case DescValueType.RAWTYPE:
                case DescValueType.REFERENCETYPE:
                default:
                    throw( new Error("Unsupported type in descriptorToObject " + t ) );
        if (undefined != f) {
            o = f(o);
    // Function: SizeInfo
    // Usage: object for holding the dialog parameters
    // Input: <none>
    // Return: object holding the size info
    function SizeInfo() {
        this.height = new UnitValue( 0, "px" );
        this.width = new UnitValue( 0, "px" );
        this.limit = false;
    // Function: NumericEditKeyboardHandler
    // Usage: Do not allow anything except for numbers 0-9
    // Input: ScriptUI keydown event
    // Return: <nothing> key is rejected and beep is sounded if invalid
    function NumericEditKeyboardHandler (event) {
        try {
            var keyIsOK = KeyIsNumeric (event) ||
                          KeyIsDelete (event) ||
                          KeyIsLRArrow (event) ||
                          KeyIsTabEnterEscape (event);
            if (! keyIsOK) {
                //    Bad input: tell ScriptUI not to accept the keydown event
                event.preventDefault();
                /*    Notify user of invalid input: make sure NOT
                       to put up an alert dialog or do anything which
                             requires user interaction, because that
                             interferes with preventing the 'default'
                             action for the keydown event */
                app.beep();
        catch (e) {
            ; // alert ("Ack! bug in NumericEditKeyboardHandler: " + e);
    //    key identifier functions
    function KeyHasModifier (event) {
        return event.shiftKey || event.ctrlKey || event.altKey || event.metaKey;
    function KeyIsNumeric (event) {
        return  (event.keyName >= '0') && (event.keyName <= '9') && ! KeyHasModifier (event);
    function KeyIsDelete (event) {
        //    Shift-delete is ok
        return ((event.keyName == 'Backspace') || (event.keyName == 'Delete')) && ! (event.ctrlKey);
    function KeyIsLRArrow (event) {
        return ((event.keyName == 'Left') || (event.keyName == 'Right')) && ! (event.altKey || event.metaKey);
    function KeyIsTabEnterEscape (event) {
        return event.keyName == 'Tab' || event.keyName == 'Enter' || event.keyName == 'Escape';
    // End Fit Image.jsx

    With Photoshop CS5 you can use Image Processor Pro and this should do what you require...
    http://blogs.adobe.com/jnack/2011/05/new-image-processor-pro-script-for-cs5.html

  • Semi-Simple Chart -- getting started help requested

    I am trying to make a smiple chart with years, campuses, and number of students. The x axis would be years, the y axis the number of students, and for each campus, a line horizonally displaying the change across time of the number of students. I don't know before hand how many campuses I will have, and I have looked for a way to represent these three values using something with the flash chart, but with no luck. Can someone direct me to either an example or some documentation on how to approach this? I looked at some anychart documentation and even built an html header with a function in it that should build a chart (I created a region to call that function), but it doesn't show up. I was thinking that I could pass the function variables that could build my chart on the fly, but even that effort hasn't gone anywhere. Please help.
    TIA,
    Deb

    JavaServer Faces requires an environment that supports at least Servlet 2.3 and JSP 1.2. It will not run on any server that supports Servlet 2.2 or earlier only. Any J2EE 1.3 or later app server meets these criteria, but it's not required (for JavaServer Faces) that you have a full J2EE server unless you need those facilities (such as EJBs) for your applications.
    The Java Web Services Developer Pack includes Tomat 5, or you can use an existing Tomcat installation (must be 4.1 or 5.0). Tomcat is pretty easy to set up (especially if you just use it standalone, and not try to run it behind the Apache HTTPD server).
    Craig MClanahan

Maybe you are looking for