Error with AppleScript - integer?

Hello, I have been making a simple script for my sister, but it does not work. It calls for an integer? I did not specify it in my program, but it calls it anyway...?
My Script:
activate
display dialog "Click Start to start importing your own kindle books!" with title "Kindle Book Uploader by Jeremy Zhang" buttons {"Cancel", "Start"} default button "Start"
property documentFolder : "documents"
tell application "Finder" to (get name of every disk whose ejectable is true)
try
          set kindleLocation to ¬
                    ((choose from list result with prompt "Select your Kindle from the list:") as text)
end try
try
          set bookFiles to ¬
                    ((choose file with prompt ¬
                              "Select kindle files to import:" of type {"public.html", "public.rtf", "com.microsoft.word.doc", "public.data.mobi", "public.plain-text", "com.adobe.pdf"} with multiple selections allowed) as text)
end try
display dialog "Please wait while the application copies the kindle books..." with title "Kindle Book Uploader by Jeremy Zhang"
tell application "Finder"
          if not (exists folder documentFolder of kindleLocation) then
  make new folder at kindleLocation with properties {name:documentFolder}
          end if
end tell
set fullKindlePath to POSIX path of (kindleLocation as alias) & "documents"
tell application "Finder"
move (bookFiles) to fullKindlePath
end tell
display dialog "Process has been done! Please eject your kindle and the files will be on the home screen of your Kindle." with title "Kindle Book Uploader by Jeremy Zhang"
And the result from running it:
tell current application
activate
end tell
tell application "AppleScript Editor"
display dialog "Click Start to start importing your own kindle books!" with title "Kindle Book Uploader by Jeremy Zhang" buttons {"Cancel", "Start"} default button "Start"
  --> {button returned:"Start"}
end tell
tell application "Finder"
get name of every disk whose ejectable = true
  --> {"JEREMY DISK"}
end tell
tell application "AppleScript Editor"
choose from list {"JEREMY DISK"} with prompt "Select your Kindle from the list:"
  --> {"JEREMY DISK"}
choose file with prompt "Select kindle files to import:" of type {"public.html", "public.rtf", "com.microsoft.word.doc", "public.data.mobi", "public.plain-text", "com.adobe.pdf"} with multiple selections allowed
  --> {alias "Macintosh HD:Users:JeremyZhang:Downloads:5 ETS SAT S.pdf"}
display dialog "Please wait while the application copies the kindle books..." with title "Kindle Book Uploader by Jeremy Zhang"
  --> {button returned:"OK"}
Result:
error "Can’t make \"documents\" into type integer." number -1700 from "documents" to integer
What am I doing wrong? Can you please correct me?
AppleScript Editor V: 2.5 (138)
AppleScript 2.2.3

Hello
Immediate cause of the error is that you're using kindleLocation, which is string, as a Finder object.
Replace this block:
tell application "Finder"
    if not (exists folder documentFolder of kindleLocation) then
        make new folder at kindleLocation with properties {name:documentFolder}
    end if
end tell
with this:
tell application "Finder"
    if not (exists folder documentFolder of disk kindleLocation) then
        make new folder at disk kindleLocation with properties {name:documentFolder}
    end if
end tell
Other than that,
- bookFiles must be list of aliases but you're coercing it to text,
- you should use "duplicate" instead of "move" to copy files,
- inadvertent try blocks will make it hard to debug the script,
- you need special code to handle user cancel in "choose from list" command.
Here's a cleanup version of your original script:
property documentFolder : "documents"
activate
display dialog "Click Start to start importing your own kindle books!" with title "Kindle Book Uploader by Jeremy Zhang" buttons {"Cancel", "Start"} default button "Start"
tell application "System Events" to set edisks to name of disks whose ejectable is true
set kindle to choose from list edisks with prompt "Select your Kindle from the list:"
if kindle = false then error number -128 -- user cancel
set kindle to kindle's item 1
set bookFiles to choose file with prompt ("Select kindle files to import:") ¬
    of type {"public.html", "public.rtf", "com.microsoft.word.doc", "public.data.mobi", "public.plain-text", "com.adobe.pdf"} ¬
    with multiple selections allowed
display dialog "Please wait while the application copies the kindle books..." with title "Kindle Book Uploader by Jeremy Zhang"
tell application "Finder"
    if not (exists folder documentFolder of disk kindle) then
        make new folder at disk kindle with properties {name:documentFolder}
    end if
    duplicate bookFiles to (kindle & ":" & documentFolder) as alias --with replacing
end tell
display dialog "Process has been done! Please eject your kindle and the files will be on the home screen of your Kindle." with title "Kindle Book Uploader by Jeremy Zhang"
Cheers,
H

Similar Messages

  • "Can't get folder 'a'" Error with Applescript

    Here is my complete applescript application. I am supposed to select a series folder, and it goes into the folder and for each season folder does something inside, including grabbing the name of the season folder. But it keep throwing an error on the line set folderName to name of folder aFolder saying it can't get name of folder "a", but the only folders inside the folder I select are Season 1, Season 2, and Season 3. Additionally, looking at the replies part of the script editor it looks like it does "M" first with no errors, and they goes to "a". I have no idea where this is coming from so help me if you can. Disregard the weird formatting, copying everything from the script editor into here messed everything up. Thanks.
    set seriesFolder to (choose folder with prompt "Select TV Series Folder") as text
    tell application "Finder" to set tvName to "list of " & (name of folder seriesFolder as text) & " episodes"
    openWebpage(tvName)
    repeat with aFolder in seriesFolder
      tell application "Finder"
      set folderName to name of folder aFolder
      set whichFile to every file of folder aFolder
      sort whichFile by name
      end tell
      set sNumber to "0" & ((characters -1 thru -1 of folderName) as string)
      set epNum to 1
      repeat with aFile in whichFile
      if epNum is less than 10 then
      set ifZero to "0"
      else
      set ifZero to ""
      end if
      set textBox to "What is episode title for S" & (sNumber as string) & "E" & ifZero & epNum & "?"
      tell application "Finder"
      set filename to name of aFile
      set nameEnding to ((characters -4 thru -1 of filename) as string)
      display dialog textBox default answer ""
      set text_returned to text returned of result
      set name of aFile to "S" & (sNumber as string) & "E" & ifZero & (epNum as string) & " - " & text_returned & nameEnding
      end tell
      set epNum to epNum + 1
      end repeat
    end repeat
    on openWebpage(input)
      set seriesName to input
      set needle to " "
      set replacement to "+"
      set searchName to search_replace(seriesName, needle, replacement)
      set address to "http://www.en.wikipedia.org/w/index.php?search=" & searchName & "&title=Special%3ASearch&go=Go"
      tell application "Safari" to open location address
    end openWebpage
    on search_replace(seriesName, needle, replacement)
      set old_delimiters to AppleScript's text item delimiters
      set AppleScript's text item delimiters to needle
      set temp_list to every text item of seriesName
      set AppleScript's text item delimiters to replacement
      set return_value to temp_list as text
      set AppleScript's text item delimiters to old_delimiters
      return return_value
    end search_replace

    Try replacing the beginning of the script with:
    set seriesFolder to (choose folder with prompt "Select TV Series Folder")
    tell application "Finder"
    set tvName to "list of " & (name of folder seriesFolder as text) & " episodes"
    tell me to openWebpage(tvName)
    repeat with aFolder in (get folders of seriesFolder)
    set folderName to name of aFolder
    (109908)

  • Automated report/ PDF conversion with AppleScript

    Hello-
    I am attempting to PDF a spreadsheet from Dropbox, and email it to a set list of recipients with AppleScript.  Much of this I have been able to figure out, but I am having some issues with the PDF conversion.  As you can see below, I am still working on sending the xls file, and have not yet been able to get AppleScript to convert a specific tab of the file to aPDF.  I expect scheduling to be handled theough crontab.
    Current script is as follows:
    tell application "Finder"
              set folderPath to folder "Macintosh HD:Users:user:Dropbox:folder:Calculated PO Sheet"
              set theFile to first file in folderPath as alias
              set fileName to name of theFile
    end tell
    set theSubject to "Current PO Report" date
    set theBody to "See attached."
    set theAddress to "recipient email"
    set theAttachment to "CALCULATED PO SHEET.xlsx"
    set theSender to "sender email"
    tell application "Mail"
              set theNewMessage to make new outgoing message with properties{subject:theSubject, content:theBody & return & return, visible:true}
              tell theNewMessage
                        set visibile to true
                        set sender to theSender
      make new to recipient at end of to recipients with properties {address:theAddress}
                        try
      make new attachment with properties {file name:theAttachment} at after the last word ofthe last paragraph
                                  set message_attachment to 0
                        on error errmess -- oops
      log errmess -- log the error
                                  set message_attachment to 1
                        end try
                        log "message_attachment = " & message_attachment
      #send
              end tell
    end tell

    Hi,
    there is a special setup for this requirement. Please see the following support note
    Reference
    Oracle Reports Output For Indian Languages Like Gujarati, Marathi [ID 980554.1]
    Roberto

  • Help with passing integer value in A.S.S

    I get an NSinternal script error while trying to pass this value can anyone help?
    Also I wonder if it is possible to pass the value to a matrix
    on clicked theObject
    tell button "checkbox" of window 1
    if integer value = 1 then
    set button "checkbox2" of window 1 to integer value = 1
    else
    set integer value to 0
    end if
    end tell
    end clicked
    I also tried:
    if state of button "checkbox" of window1 is 1 then
    set the state of button "checkbox2" of window1 to 1
    end if
    Message was edited by: Doug Bassett

    I've been following this thread and trying to figure out how to make this work. I was getting inconsistent results or errors with most of the code that has been posted. But I finally got it working... at least on a Leopard machine (not sure if this could have changed between Tiger and Leopard so your mileage may vary).
    What I found was that a checkbox button that's located directly in a window seems to have a state that's equal to 0 when it's unchecked and 1 when it's checked. But a checkbox cell that's contained within a matrix seems to have a state that's set to either _off state_ or _on state_. Trying to set a cell's state to 0 or 1 simply wasn't working right for me. So I get the state of the "selectall" checkbox button (which is a 0/1) and transform it to either "off state" or "on state" before setting the states of the checkbox cells in the matrix.
    Here's my code:
    on clicked theObject
    set n to name of theObject
    if n = "selectall" then
    set s to state of theObject
    log "state: " & s
    if s = 0 then
    set newState to off state
    else
    set newState to on state
    end if
    repeat with i from 1 to count of cells of matrix "directories" of window "main"
    tell cell i of matrix "directories" of window "main"
    set state to newState
    end tell
    end repeat
    return
    end if
    if n = "logStatesBtn" then
    logStates()
    return
    end if
    end clicked
    on logStates()
    log "Logging states:"
    set s to state of button "selectall" of window "main"
    log "selectall checkbox: " & s
    repeat with i from 1 to count of cells of matrix "directories" of window "main"
    tell cell i of matrix "directories" of window "main"
    set s to state
    end tell
    log "Cell " & i & ": " & s
    end repeat
    end logStates
    Note the "logStates" handler is just something I connected up to a "logStatesBtn" button in my window that lets me spit out the states of all the checkboxes into the console log. This is how I actually discovered that the cells were set to "off state" or "on state".
    Steve

  • [Solved] Black Screen after KDM - plasma-desktop error with libpng

    Hey,
    i just wanted to log in to my arch session, but after KDM theres just a black screen.
    I found out, that all programs startet via krunner are working.
    So it's just plasma-desktop, what makes the problems
    plasme-desktop
    LONG OUTPUT AND IN THE END
    libpng warning: IDAT CRC error
    lippng error: PNG unsigned integer out of range
    thats it... plasma-netbook works without any problems... also window effects are working
    Dont know wheter its any help, but i dualboot with macOS and share the desktop, where 2 .jpgs are stored, dont know wether this is important...
    Edit:
    I've tried to delet the jpgs in the desktop folder and uninstalled kde-wallpapers. Still no luck
    I've also tried to downgrade libpng to 1.5.14, but when i reboot, kdm wont start.... maybe there's something i haven't thought through....
    However the Output changed a bit, heres the full output:
    [markus@MacBook ~]$ plasma-desktop
    QDBusConnection: session D-Bus connection created before QCoreApplication. Application may misbehave.
    QDBusConnection: session D-Bus connection created before QCoreApplication. Application may misbehave.
    Fontconfig warning: "/etc/fonts/conf.d/50-user.conf", line 14: reading configurations from ~/.fonts.conf is deprecated.
    QDBusObjectPath: invalid path ""
    QDBusObjectPath: invalid path ""
    QGraphicsLinearLayout::insertItem: cannot insert null item
    QGraphicsLinearLayout::insertItem: cannot insert null item
    plasma-desktop(1757)/libplasma Plasma::isPluginVersionCompatible: unversioned plugin detected, may result in instability
    13:11:22.331 Info [Appl. Thread] YaWP::YaWP (Line 95):
    13:11:22.331 Info [Appl. Thread] YaWP::YaWP (Line 96): yaWP 0.4.2 compiled at Mar 30 2012 22:19:57 for KDE 4.8.1 (4.8.1)
    13:11:22.332 Info [Appl. Thread] YaWP::YaWP (Line 97): yaWP 0.4.2 is running on KDE 4.10.4
    13:11:22.332 Info [Appl. Thread] YaWP::YaWP (Line 98):
    plasma-desktop(1757)/libplasma Plasma::isPluginVersionCompatible: unversioned plugin detected, may result in instability
    plasma-desktop(1757)/libplasma Plasma::isPluginVersionCompatible: unversioned plugin detected, may result in instability
    plasma-desktop(1757)/libplasma Plasma::isPluginVersionCompatible: unversioned plugin detected, may result in instability
    plasma-desktop(1757)/libplasma Plasma::isPluginVersionCompatible: unversioned plugin detected, may result in instability
    13:11:22.735 Debug [Appl. Thread] YaWP::loadConfig (Line 529): "wunderground" "Nuernberg, Germany" "Germany" "de" "airport:EDDN" "Europe/Berlin" "DE"
    13:11:22.746 Info [Appl. Thread] WundergroundIon::WundergroundIon (Line 203): WundergroundIon 0.4.2 compiled at Mar 30 2012 22:20:16 for KDE 4.8.1 (4.8.1)
    13:11:22.746 Debug [Appl. Thread] WundergroundIon::getWeatherData (Line 758): QUrl("http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=EDDN")
    13:11:22.747 Debug [Appl. Thread] WundergroundIon::getWeatherData (Line 819): Added XmlWeatherData for "airport:EDDN"
    libpng error: bad adaptive filter value
    Thanks for any help!
    Last edited by markus2107 (2013-06-17 14:52:06)

    Should have done that earlier... renaming .kde4
    Now it workes... and after uninstalling yawp-plasmoid i renamed .kde4... everything's fine now!
    So if anybody else runs in this problem too, my advice: check your aur-plasmoids!

  • Error with gregoriancalendar

    I'm having an error with the gregoriancalendar class.
    I have a class that gets an initial date froma database, and iterate until today.
    The problem is that its showing that today is day 262 and we are in day 232 of the year.
    Whats the problem????
    Any help will be appreciate.
    the code is bellow:
    String sql2 = "Select d02inter from cen02";
              try{
              PreparedStatement st4 = cnn3.prepareStatement(sql2);
              ResultSet rs2 = st4.executeQuery();
              dataatual = null;
              while (rs2.next()){
                   String dataint = rs2.getString("d02inter");
                   Integer ano_int = Integer.valueOf(dataint.substring(1,5));
                   Integer mes_int = Integer.valueOf(dataint.substring(5,7));
                   Integer dia_int = Integer.valueOf(dataint.substring(7));
                   Calendar calend_int = new GregorianCalendar(ano_int,mes_int,dia_int);
                   Calendar calend_hoje = new GregorianCalendar();
                   Calendar calendwork = (GregorianCalendar)calend_int.clone();
                   while((calendwork.compareTo(calend_hoje))<0){
                        Integer diadoano=calendwork.get(Calendar.DAY_OF_YEAR);
                        Integer ano = calendwork.get(Calendar.YEAR);
                        dataatual=(ano*1000)+diadoano;
                        if(calendwork.equals(calend_int)){
                             if(mp.containsKey(dataatual)){
                                  bmhBean bm = (bmhBean)mp.get(dataatual);
                                  bm.entrou++;
                                  mp.put(dataatual,bm);
                             }else{
                                  bmhBean bm = new bmhBean();
                                  bm.entrou++;
                                  mp.put(dataatual,bm);
                        if(mp.containsKey(dataatual)){
                             bmhBean bm = (bmhBean)mp.get(dataatual);
                             bm.inter++;
                             mp.put(dataatual,bm);
                        }else{
                             bmhBean bm = new bmhBean();
                             bm.inter++;
                             mp.put(dataatual,bm);
                        calendwork.add(Calendar.DATE,1);
              }

    Yes I agree with Wildcard82
    The GregorianCalendar javadoc defines the month 0 based (0 - 11)
    so you must be careful when creating a Gregorian calendar by substracting 1 to your month number (if 1 - 12), and if passing it back to an int of the type 1 - 12, to add a respective 1e on the
    get(GregorianCalendar.MONTH)method
    I recommend what i did to evade dealing with this, I'm used to save dates in the yyyymmdd format, and month being from 1-12, so I created two methods
    a) int2GregorianCalendar(int date), which takes that int type and returns the correct GregorianCalendar, with what was defined above.
    b) GregorianCalendar2int(GregorianCalendar date) which is the opposite.
    Hope it helps, cya.

  • Making and opening folder with applescript

    I'm trying to create and open a folder with applescript, but my script gives an error...
    This is what i've written but can't figure out what i'm doing wrong. I hope you can help me!
    tell application "Finder"
    activate
              set the_folder to "106_WDJZ Eigen Magazine 20pp_Foto"
              set myfolder to make new folder at "Press4:10. Specials:N19. WDJZ Eigen Magazine 20pp:F. Foto:" with properties {name:the_folder}
              set openmap to (myfolder & the_folder)
    end tell
    Thank you very much in advance

    Thank you both for your awnsers. I really appreciate it! I was trying to create a folder (at "Press4:10. Specials:N19. WDJZ Eigen Magazine 20pp:F. Foto:") with a name (106_WDJZ Eigen Magazine 20pp_Foto) and after the folder is created I want the scrpt to open the folder.
    The in FileMakerPro (calculated) applescript is now working and look like this:
    "tell application \"Finder\"" & ¶ &
    "set the_folder to \"" & Editie_standaardgegevens::UitgaveID & "_" & Editie_standaardgegevens::Editienaam_intern & "_Foto" & "\"" & ¶ &
    "set sub_folder to \"Press4:10. Specials:" & Editie_standaardgegevens::Editienaam_intern_totaal & ":F. Foto:\"" & ¶ &
    "set myfolder to make new folder at sub_folder with properties {name:the_folder}" & ¶ &
    "set openfolder to (sub_folder & the_folder & \":\")" & ¶ &
    "open folder openfolder" & ¶ &
    "activate" & ¶ &
    "end tell"

  • How can I open a document with applescript without the doc. window opening.

    How can I open a document with applescript without opening the document window and speak the text of the document?  I can get it to open the file but the doc window always opens up. 

    try
              set pathToMyFolderOnDesktop to ("Macintosh HD:Users:jodyconnor:Desktop:") & "Dsource:" as alias
              set rnd to (random number from 1 to 6)
              set rndFileName to (rnd as text) & ".scpt"
              set FullPath to pathToMyFolderOnDesktop & rndFileName as text
              set myScript to load script (FullPath as alias)
      run script myScript
    on error the error_message number the error_number
              display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
              return
    end try
    This code answered my question:  Hats off to Digimonk from stackoverflow and Darrick Herewe from stackoverflow.

  • Download image from URL with applescript

    I want to download an image from an website (and internal IP address) using applescript,
    now I have found a script that works (Download jpeg image to folder with AppleScript from URL).
    But, the web page requires a username and password...
    When I convert the downloaded JPEG into a HTML by simply changing the extension, quick look displays the webpage's 401 unauthorized error page...
    Does someone know how to make the applescript input the username and password?

    The answer depends on how the authentication is managed.
    There are two common ways of implementing authentication in web browsers and knowing which one is used here is essential to scripting the request. One is also significantly harder than the other.
    The first (easy) way is that the username and password can be submitted with the request. This is the original model and is easy to script - if you're using the curl model then it's just a matter of adding the -user switch to the command line:
           -u, --user <user:password>
                  Specify the user name and password to use for server authentica-
                  tion. Overrides -n, --netrc and --netrc-optional.
    This model is a little less secure, though, but might still be used on internal sites since it's easy to implement.
    The other option is that the site uses cookies - you log in via a web form and the server gives your cookie which you then send with subsequent requests and are used to validate your access. This is a more secure, but is harder to implement because there is a multi-step process - login via the web form, capture the cookie, submit the cookie with the download request.
    If you're not familiar with the different methods it can sometimes be hard to tell which one you need, and since it's an internal site there's no way anyone else can check... so you'll need to describe how you login to the site (or are prompted for authentication) before anyone can provide a direct answer.

  • Error with - addStylesToDocument(doc); please help

    Hello, this is my unfinished code for a simple program I am writing. Basically I have a menu and buttons, and am looking to add a JTextPane. I think I have all the code there, except when compiling I am having an error with line addStylesToDocument(doc); if I comment this out then nothing happens but the program runs as normal (before I added the JTextPane code) the error I am getting is "non-static method addStylesToDocument(javax.swing.text.StyledDocument) cannot be referenced from a static context" this makes a little sence to me but not enough to be able to correct it as I am pretty much a beginner...
    If anyone has any suggestions to fix this I would appreciate your input.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class ShoppingCart extends JPanel
                            implements ActionListener {
        protected JButton bapple, borange, bbanana, bstrawberry, blemon, bgrape, b7, b8, b9, b10;
        public JMenuBar createMenuBar() {
         JMenuBar menuBar;
         JMenu menu, submenu;
         JMenuItem menuItem;
         JRadioButtonMenuItem rbMenuItem;
         JCheckBoxMenuItem cbMenuItem;
    menuBar = new JMenuBar();
    menuBar.setBackground(Color.white);
          menu = new JMenu("A Menu");
          menu.setBackground(Color.white);
            menu.setMnemonic(KeyEvent.VK_A);
            menu.getAccessibleContext().setAccessibleDescription(
                    "The only menu in this program that has menu items");
            menuBar.add(menu);
          //a group of JMenuItems
          menuItem = new JMenuItem("A text-only menu item",
                                     KeyEvent.VK_T);
            //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
             menuItem.setBackground(Color.white);
             menuItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_1, ActionEvent.ALT_MASK));
           menuItem.getAccessibleContext().setAccessibleDescription(
           "This doesn't really do anything");
            menu.add(menuItem);
            ImageIcon icon = createImageIcon("/orange.gif");
            menuItem = new JMenuItem ("Both text and icon", icon);
            menuItem.setMnemonic(KeyEvent.VK_B);
            menuItem.setBackground(Color.white);
          menu.add(menuItem);
          menuItem = new JMenuItem(icon);
          menuItem.setMnemonic(KeyEvent.VK_D);
          menuItem.setBackground(Color.white);
          menu.add(menuItem);
          //a group of radio button menu items
          menu.addSeparator();
          ButtonGroup group = new ButtonGroup();
          rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
          rbMenuItem.setSelected(true);
          rbMenuItem.setMnemonic(KeyEvent.VK_R);
          rbMenuItem.setBackground(Color.white);
          group.add(rbMenuItem);
          menu.add(rbMenuItem);
          //a group if check box menu items
          menu.addSeparator();
          cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
          cbMenuItem.setMnemonic(KeyEvent.VK_C);
          cbMenuItem.setBackground(Color.white);
          menu.add(cbMenuItem);
          cbMenuItem = new JCheckBoxMenuItem("Another one");
          cbMenuItem.setMnemonic(KeyEvent.VK_H);
          cbMenuItem.setBackground(Color.white);
          menu.add(cbMenuItem);
          //a submenu
          menu.addSeparator();
          submenu = new JMenu("A submenu");
          submenu.setBackground(Color.white);
          submenu.setMnemonic(KeyEvent.VK_S);
          menuItem = new JMenuItem("An  item in the submenu");
          menuItem.setAccelerator(KeyStroke.getKeyStroke(
          KeyEvent.VK_2, ActionEvent.ALT_MASK));
          menuItem.setBackground(Color.white);
          submenu.add(menuItem);
          menuItem = new JMenuItem("Another item");
          menuItem.setBackground(Color.white);
          submenu.add(menuItem);
          menu.add(submenu);
          //Build second menu in the menu bar
          menu = new JMenu("Another Menu");
          menu.setBackground(Color.white);
          menu.setMnemonic(KeyEvent.VK_N);
          menu.getAccessibleContext().setAccessibleDescription(
          "This menu does nothing");
          menuBar.add(menu); 
    return menuBar;
        public ShoppingCart() {
            ImageIcon appleButtonIcon = createImageIcon("/apple.gif");
            ImageIcon orangeButtonIcon = createImageIcon("/orange.gif");
            ImageIcon bananaButtonIcon = createImageIcon("/banana.gif");
            ImageIcon strawberryButtonIcon = createImageIcon("/strawberry.gif");
            ImageIcon lemonButtonIcon = createImageIcon("/lemon.gif");
            ImageIcon grapeButtonIcon = createImageIcon("/grape.gif");
            bapple = new JButton(null,  appleButtonIcon);
            bapple.setVerticalTextPosition(AbstractButton.CENTER);
            bapple.setBackground(Color.white);
            bapple.setHorizontalTextPosition(AbstractButton.LEADING);
            bapple.setMnemonic(KeyEvent.VK_D);
            bapple.setActionCommand("apple");
            borange = new JButton(null, orangeButtonIcon);
            borange.setVerticalTextPosition(AbstractButton.BOTTOM);
            borange.setBackground(Color.white);
            borange.setHorizontalTextPosition(AbstractButton.CENTER);
            borange.setMnemonic(KeyEvent.VK_M);
            borange.setActionCommand("orange");
            bbanana = new JButton(null, bananaButtonIcon);
            bbanana.setBackground(Color.white);
            bbanana.setMnemonic(KeyEvent.VK_E);
            bbanana.setActionCommand("banana");
            bstrawberry = new JButton(null,  strawberryButtonIcon);
            bstrawberry.setVerticalTextPosition(AbstractButton.CENTER);
            bstrawberry.setBackground(Color.white);
            bstrawberry.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
            bstrawberry.setActionCommand("strawberry");
            blemon = new JButton(null,  lemonButtonIcon);
            blemon.setBackground(Color.white);
            blemon.setVerticalTextPosition(AbstractButton.CENTER);
            blemon.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
            blemon.setActionCommand("lemon");
            bgrape = new JButton(null,  grapeButtonIcon);
            bgrape.setBackground(Color.white);
            bgrape.setVerticalTextPosition(AbstractButton.CENTER);
            bgrape.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
            bgrape.setActionCommand("grape");
            /*b7 = new JButton(null,  leftButtonIcon);
            b7.setVerticalTextPosition(AbstractButton.CENTER);
            b7.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
            b8 = new JButton(null,  leftButtonIcon);
            b8.setVerticalTextPosition(AbstractButton.CENTER);
            b8.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
            b9 = new JButton(null,  leftButtonIcon);
            b9.setVerticalTextPosition(AbstractButton.CENTER);
            b9.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
            b10 = new JButton(null,  leftButtonIcon);
            b10.setVerticalTextPosition(AbstractButton.CENTER);
            b10.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
            //Listen for actions on buttons
            bapple.addActionListener(this);
            borange.addActionListener(this);
            bbanana.addActionListener(this);
            bstrawberry.addActionListener(this);
            blemon.addActionListener(this);
            bgrape.addActionListener(this);
            bapple.setToolTipText("Apple.");
            borange.setToolTipText("Orange.");
            bbanana.setToolTipText("Banana.");
            bstrawberry.setToolTipText("Strawberry.");
            blemon.setToolTipText("Lemon.");
            bgrape.setToolTipText("Grape.");
           /* b7.setToolTipText("7");
            b8.setToolTipText("8");
            b9.setToolTipText("9");
            b10.setToolTipText("10");
            //Add Components to this container, using the default FlowLayout.
            add(bapple);
            add(borange);
            add(bbanana);
            add(bstrawberry);
            add(blemon);
            add(bgrape);
           /* add(b7);
            add(b8);
            add(b9);
            add(b10);*/
        public void actionPerformed(ActionEvent e) {
            if ("apple".equals(e.getActionCommand())) {
           String  input1 =  JOptionPane.showInputDialog( "How many apples would you like to purchase?" );
            int  number1 = Integer.parseInt( input1 );
             if ("orange".equals(e.getActionCommand())) {
           String  input2 =  JOptionPane.showInputDialog( "How many oranges would you like to purchase?" );
           int  number2 = Integer.parseInt( input2 );
               if ("banana".equals(e.getActionCommand())) {
           String  input3 =  JOptionPane.showInputDialog( "How many bananas would you like to purchase?" );
           int  number3 = Integer.parseInt( input3 );
             if ("strawberry".equals(e.getActionCommand())) {
           String  input4 =  JOptionPane.showInputDialog( "Enter weight of strawberries : " );
           int  number4 = Integer.parseInt( input4 );
             if ("lemon".equals(e.getActionCommand())) {
           String  input5 =  JOptionPane.showInputDialog( "How many lemons would you like to purchase?" );
           int  number5 = Integer.parseInt( input5 );
             if ("grape".equals(e.getActionCommand())) {
           String  input6 =  JOptionPane.showInputDialog( "Enter weight of grapes : " );
           int  number6 = Integer.parseInt( input6 );
        /** Returns an ImageIcon, or null if the path was invalid. */
        protected static ImageIcon createImageIcon(String path) {
            java.net.URL imgURL = ShoppingCart.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
    //Create and set up the window.
            JFrame frame = new JFrame("Shopping Cart");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            ShoppingCart newContentPane = new ShoppingCart();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane);
            newContentPane.setBackground(Color.white);
           frame.setJMenuBar(newContentPane.createMenuBar());
            //Display the window.
            frame.pack();
            frame.setVisible(true);
            String[] initString =
            { /* ...  fill array with initial text  ... */ };
            String[] initStyles =
            { /* ...  fill array with names of styles  ... */ };
            JTextPane textPane = new JTextPane();
            StyledDocument doc = textPane.getStyledDocument();
            addStylesToDocument(doc);
            //Load the text pane with styled text.
            try {
            for (int i=0; i < initString.length; i++) {
            doc.insertString(doc.getLength(), initString,
    doc.getStyle(initStyles[i]));
    } catch (BadLocationException ble) {
    System.err.println("Couldn't insert initial text into text pane.");
    }protected void addStylesToDocument (StyledDocument doc) {
    Style def=new StyleContext ().getStyle (StyleContext.DEFAULT_STYLE);
    Style heading = doc.addStyle ("bold", null);
    StyleConstants.setFontFamily (heading, "SansSerif");
    StyleConstants.setBold (heading, true);
    StyleConstants.setFontSize (heading,30);
    // * The next 3 don't work if that line is commented out
    StyleConstants.setAlignment (heading, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove (heading, 10);
    StyleConstants.setSpaceBelow (heading, 10);
    public static void main() {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();

    CPie wrote:
    o..k.
    I see that you have run out of helpfulness for this session, What the ....? I just told you to add your jtextfield to a jpanel or some other visible component to be seen.
    it is getting late here I will take my business elsewhere tomorrow rather than waiting up for a response which shows you realllly need to find something better to do! And thanks for the help earlier. That was actually useful whereas this wasn't, I'm sure you knew that already,You know that we are all volunteers here. Any time spent here helping you is time away from our friends and families. A little more appreciation is definitely in order or go somewhere else and pay for your help.

  • How to detect beep sounds with AppleScript?

    I have a small dilema.
    I created a script that I know generates the standard mac error sound a.k.a. beep sound. I want to detect cases where it does not generate. IS there any way to verify with applescript if the beep sound plays at all?
    I mean I hear it, but I want it logged as beep sound played/not played.
    any ideas are welcome!

    You need to generalize the problem to how do you detect an error in another application.
    Typically, aplications will return an error code when they find an error.  This will cause an excpetion in your applescript app. To detect the error you put the call in a try block.
    So what program are you calling?
    Did you wrie the other app?  If so, return a non-zero error code.
    Robert

  • Problems with AppleScript and MS Office 2011

    The script below used to work great for converting MS Word files to PDF files.  However, sometime during the last few months it has stopped working and will no longer compile without error.  Possibly after upgrading to Mavericks but I'm not exactly sure when it stopped working, could have been an update to Office.  Anyway, the error I'm getting when I compile is a Syntax Error, "Expected end of line but found class name".  The editor highlights "document" in the line "set the_doc to active document".  I'm not very familiar with Applescript but I have opened the scripting dictionary for Microsoft Word in the Applescript editor and I do see "active document" as a property of the "document" object.  So why doesn't the compiler recognize it?  Am I missing something obvious or was there some sort of change in Mavericks that broke this functionality?
    I've been pulling my hair out trying to get this script working again  but I have not had any luck.  I've tried uninstalling and reinstalling Microsoft Office per instructions from Microsoft.  I have all the latest updates and patches. Any help would be greatly appreciated.
    Here is the original code which used to work just fine.
    -- Stephen Norum
    -- [email protected]
    property pdf_ext : ".pdf"
    on remove_extension(file_path)
        -- remove the extension if it exists
        set stripped to do shell script ("F=" & quoted form of file_path & " ; echo ${F%.*}")
        return stripped
    end remove_extension
    on get_pdf_path(doc_path)
        set doc_path to remove_extension(doc_path)
        -- Try the simple name first
        set pdf_path to (doc_path & pdf_ext)
        -- Otherwise, number the pdfs
        set counter to 1
        tell application "Finder"
            repeat while (exists pdf_path)
                set pdf_path to (doc_path & " " & counter & pdf_ext)
                set counter to counter + 1
            end repeat
        end tell
        return pdf_path
    end get_pdf_path
    on run {input, parameters}
        repeat with file_name in input
            tell application "Microsoft Word"
                open file_name
                set the_doc to active document
                set doc_path to path of the_doc
            end tell
            set pdf_path to get_pdf_path(doc_path)
            tell application "Microsoft Word"
                save as active document file name pdf_path file format format PDF
                close active document
            end tell
        end repeat
        tell application "Finder"
            activate
        end tell
        return input
    end run

    try this syntax:
                        tell application "Microsoft Word"
      save as (active document) file name pdf_path file format PDF
                        end tell
    Apparently they changed the enumeration label from format PDF to just plain old PDF without bothering to update the scripting dictionary or ensure backward compatibility. If you want to know how they managed to do that, they are still not using sdef or even scriptSuite xml files, but are loading the scripting information from old-school (i.e. os 8 or os 9 style) resource files.
    I've occasionally considered writing Microsoft a proposal to redo the Office scripting dictionaries so they are less crazy-making, but I'm not sure I'd survive the attempt.

  • Converting Word 5.1 files with Applescript

    As Microsoft office 2011 currently no longer support Word 5.1 I'm using the previous Office 2004. I can read 5.1 files and saved themmanually as .doc files on Snow Leopard.
    However the files are many and I have this script
    set inputfolder to (choose folder) as text
    set destFolder to (choose folder) as text
    set theFiles to list folder inputfolder without invisibles
    activate application "Word"
    repeat with x from 1 to count of theFiles
              set thefile to item x of theFiles
              set inputfile to (inputfolder & thefile)
              tell application "Word"
      open document inputfile
                        save document 1 in (destFolder & thefile & ".doc")
      close document 1 saving no
              end tell
    end repeat
    Trying to open the files I need to convert and save them in a different folder.
    However I always get an error from AppleScript Version 2.3 (118)
    error "Microsoft Word got an error: document \"Disk:Word_Files:a:  New Files:General Stuff:conv\" doesn’t understand the open message." number -1708 from document "Disk:Word_Files:a:   New Files:General Stuff:conv"
    If anyone can help or give another solution to batch convert I will be very glad and happy new Year to all

    Thanks all however if anyone is interested this is the solution it works till the current office version:
    set inputfolder to (choose folder) as text
    set destFolder to (choose folder) as text
    set theFiles to list folder inputfolder without invisibles
    activate application "Microsoft Word"
    repeat with x from 1 to count of theFiles
              set thefile to item x of theFiles
              set inputfile to (inputfolder & thefile)
              tell application "Microsoft Word"
      open file inputfile
      save as document 1 file name (destFolder & thefile & ".doc")
      close document 1 saving no
              end tell
    end repeat
    The only drawback is:
    if the selected destination folder is inside the input folder the script will give error and stop
    however this doesn't happen if the "destination folder" is somewhere elese from the selected input folder
    Regards and Happy new year

  • New permissions errors with OSX 10.5

    I have a script that I have been using to transfer files from one account to another under OSX 10.4. However, with the change to 10.5, I have started to get permissions errors. Just wondering what has changed.
    The shell script runs under an executable wrapper (for security), with the “s” permissions bit set:
    #define REAL_PATH "/Users/Shared/transferFileScript"
    main(ac, av)
    char **av;
    execv(REAL_PATH, av);
    The permissions are:
    -rwsr-xr-x 1 root myadminacct 11532 Apr 22 2005 wrapper
    The script itself is as follows:
    #!/bin/sh
    mkdir /Users/"$1"/Desktop/Transferred_Files
    /Developer/Tools/cpMac -r "$2" /Users/"$1"/Desktop/Transferred_Files/
    chown -R "$1" /Users/"$1"/Desktop/Transferred_Files
    Here are its permissions:
    -rw-r-xr-x 1 root myadminacct 180 Dec 31 2004 transferFileScript
    The whole mess is executed via an AppleScript (which provides the user interface). No special permissions on that.
    As I said, it worked fine in 10.4. Any thoughts as to what is going wrong? Thanks in advance.
    Eric

    Eric S wrote:
    Thanks for the suggestion. In doing an "id", it appears that Leopard has left all the group settings alone (I did an upgrade, rather than a clean install).
    OK, I did that initially. However, the groups with gid and name the same as your uid and name don't really exist, so I'd bet this is still the cause of the problem.
    Maybe I should have specified where the error is occurring... The AppleScript runs and it executes the wrapper, which in turn begins executing the Unix script. The permission error occurs when the Unix script tries to execute the "mkdir" command.
    I can't help with AppleScript, but if it is failing on a "mkdir" you should look at the permissions on the parent directory.

  • Problem applying stroke miter limit with applescript

    Hi, I have a bit of a problem with applescript, Im creating a Text item and setting the stroke to 0.4pt then i want the stroke miter limit to be set to 2 but it wont work i get :-
    Adobe Illustrator got an error: Can’t set properties of text frame 1 of layer 1 of document 1 to {stroke miter limit:2}. (error -10006)
    but im am able to apply a stroke miter limit of 2 on a path item, is there a way of converting the text frame to a path item then applying the stroke miter limit to it.
    heres my script :-
    on TicketFront_(posX, posY)
         tell application "Adobe Illustrator"
              activate
              set ticketItem to make new text frame in theDoc with properties {contents:{"Some Text"}, position:{(35.7 + posX) * 2.834645, (173.5 - posY) * 2.834645}}
              set properties of the text of ticketItem to {text font:text font "Raleway-Thin", size:5.54, justification:center, fill color:{class:spot color info, tint:100.0, spot:spot "PANTONE 4535 U" of document 1}, stroke color:{class:spot color info, tint:100.0, spot:spot "PANTONE 4535 U" of document 1}, horizontal scale:126.46, stroke weight:0.4}
              --This next line gives me the error
              set properties of ticketItem to {stroke miter limit:2}
         end tell
    end TicketFront_
    ive also tryed putting convert to paths ticketItem in the script which converts the text to paths but the stroke miter limit still dont work.
    Thanks in Advance.
    uk_rules_ok

    you're not targeting the paths yet, you have to drill down to the letters (paths)
    textFrame to Outlines returns a Group
    inside this group you have compound paths
    inside each compound path you have the actual paths, one or more, depending on the letter
    try something like this, (not actual code, I'm just guessing)
    set ticketGroup to convert to paths ticketItem
    set ticketCompoundPath to first compoundPath in ticketGroup
    set ticketPath to first pathItem in ticketCompoundPath
    now you can set the miter limit property of ticketPath

Maybe you are looking for

  • XE Database home page gone after APEX 3.2 upgrade

    I just upgraded the version of HTMLDB/APEX on my XE database from 2.0 to APEX 3.2. All went well, however, the database home page seems to have disappeared. When I go to Start|Programs|Oracle Database 10g Express Edition|Database home page, I now get

  • How can I change the security questions on my account without calling Apple support?

    Important to note that when I try to change it on the Password and Security page on My Apple ID, it keeps asking me to answer my security questions, which I can't remember the exact answer to. I've also tried changing my Apple ID password, but then i

  • Flash Builder 4 Installation Problems

    I'm having trouble using Flash Builder 4. I first tried to use it as a plugin for eclipse, which didn't work, as I got an error when trying to open .mxml files. The error is the same one discussed in another discussion: a null pointer exception. I tr

  • DL speed never over 400kbps

    I have a homehub 3, I have also dis-connected the bel-wire, I have tried the master-socket, I have left the hub running for more than 12 days and I don't know what else to do. I am on option 3 on the BT contract. These are my BT speedtest results tod

  • Replacement for inner join.

    I have the following SELECT stmt with inner join which is taking more time to execute......Kindly help me how to improve performance SELECT AWERKS AMATNR AMBLNR AMJAHR AMENGE ABWART A~SHKZG                 AAUFNR  BBUDAT                INTO CORRESPON