Using AppleScript to return name in Automator

Trying to create an AppleScript action to return the name of the item handed to it by the Automator. As it the script fails to complete with and error "Check the actionʼs properties.." If I remove "name of" in the return command, i get the path of target of the input returned. What is the datatype being handed from Automator into the AppleScript? I'm wanting to output a string datatype to use this input name later on.
Thanks,
Chris

Try using:
return name of (info for item 1 of input)
(70482)

Similar Messages

  • Using Applescript (or Automator) to delete Albums

    When you import folders into Aperture, it creates for every folder an Album "Images from:" whatever the folder name is. Is there a way using Applescript that I can easily delete those albums? They are essentially useless as they stand to me. I am importing a large number of folders, so I am getting those albums all over my Aperture library.

    The short answer is yes you can use apple script to do that - there is virtual no documentation you will have to take a look at all the methods that aperture exports to figure out what you have to do. If you are new to applescript/automator you may want to think twice about taking that on.
    Just a note regarding import - There are three ways to import into aperture:
    1) the normal way - import images - this takes all the images in a folder and imports them into an existing or new project.
    2) if you happen to be clicked on an existing project you can use import folders as albums (what I think you are doing).
    3) if you happen to be clicked on the library level or a blue folder that same option number 2 changes into import folders as projects.
    Using the combination of the three may ease the import a little with out resorting to applescript/automator unless you are familiar with using those tools that may be rough going.
    RB

  • Automating Final Cut Express using AppleScript?

    Hello,
    just another question: is it possible to use AppleScript (or something similar) with Final Cut Express?
    And if so, where to find a good reference?
    I have some DV movies and a for each a csv containing the In and Out Points for the subclips, including their names and comments about the contained action, date, place, light and so on.
    At moment I'm doing everything manually, but that's time killing, so I'm looking for how to automate this.
    Thank you.

    Comma Separated Values (see http://tools.ietf.org/html/rfc4180).
    In other words: a machine readable table sheet.

  • Having trouble using applescript to save pdf as excel spreadsheet

    I have been trying to use applescript to create an automator action to convert some downloaded PDF's to .xlsx format.  After reviewing a good bit of the SDK documentation, I came up with the following scripting:
    tell application "Adobe Acrobat Pro"
                                  open theFile
                                  save front document to file theNewFile using conversion "com.adobe.acrobat.xlsx"
      close front document
    end tell
    This script works fine when I use the "com.adobe.acrobat.plain-text" conversion or the png or jpeg conversion. However, I cannot get it to work with "com.adobe.acrobat.xlsx" or "com.adobe.acrobat.spreadsheet".  Note that although I didn't copy the code here that sets theNewFile variable, I have been changing it to the appropriate file extension when changing conversion strings.
    When I execute the script using one of the problem conversion strings, Acrobat opens the file successfully, but it just sits there, as if it does not understand the save command at all.
    I guess I should mention that the whole goal here is to actually convert the PDF's to CSV eventually.  The next step was going to be to open the file in Excel and save as CSV.  If anyone knows a *free* way to go straight from PDF to CSV using Applescript/Automator without having to go through all these other programs, I would be very appreciative for the suggestion.  This conversion is just a small part of a very lengthy workflow but it is causing me the most trouble.

    Hello Jonathan,
    Ok i have only one final question.
    Do you know how to work in photoshop, don't you? Ok i think yes.
    Well i have 2 ways to do that, i did one action from photoshop that will get the image inside folder and will convert this image in pdf. Abouve the line of script
    that you have to attach to folder action and the action for Photoshop.
    About the action for Photoshop give me your email address and I send you, or do it your self. You have to do this: open one image in JPG, go to action, go new set, put your name of set, put the name of action if you like you can change the name, go print with preview, print and set save as PDF close your file and stop the action.
    Now that you have to do is put all your files inside your folder and leave the Photoshop do it for you, ok?
    Good Luck
    Hack
    property speak_alert : false -- if true, the script will speak the alert. If false, the script will display an alert dialog
    property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.
    property copychecksindicator : false
    property itemcheck_delaytime : 2
    property foldercheck_delaytime : 3
    property speciallabelindex : 7
    on adding folder items to this_folder after receiving added_items
    if copychecksindicator is true then
    set the added_items to my checkaddeditems(the added_items)
    if the added_items is {} then return "no vaild items"
    end if
    tell application "Finder"
    activate
    set this_folder to choose folder with prompt "pdf"
    set these_files to every file of folder this_folder
    end tell
    tell application "Finder"
    repeat with i from 1 to number of items in these_files
    set this_path to (item i of these_files) as string
    tell application "Adobe Photoshop CS2"
    launch
    open file (this_path as string)
    set this_files to current document
    do action "Jpg" from "Jpg para Pdf"
    end tell
    end repeat
    end tell
    end adding folder items to

  • How I generate index markers using Applescript and tagged text!

    One of the challenges I've faced in automating the book making process using Applescript with inDesign is that there don't seem to be any AS commands for making new index markers (anyone please correct me I if I'm wrong about this).
    I've tried various js scripts which do an OK job, but they don't make the actual native markers. This means you have to wait until the book (consistiing of multiple ID files) is complete (so that all the page numbers have been established) to generate the index.
    Recently, I read a tweet from someone with a link to a technique which uses tagged text and find and replace with GREP to edit the tags, inserting the tagged text index tags in the text file and then re-placing the text file in the ID page. In itself, this works great. But I'm dealing with literally thousands of separate text frames, none of them connected in a story.
    The books typically consist of around 1200 pages with almost that many people, each of whose names I need to index with "Lastname, Firstname" references. And those particular strings don't (can't) appear anywhere on the pages. There will also be about 50 ID files all combined into one book. So it is imperative that I have ID generate the native index markers. To help keep things straight and efficient, I'm creating separate small text frames to hold the lastname, firstname strings. I created an object style for these frames which sets the attributes to "nonprinting", and I place the frames in the margin.
    Then I realized that I don't actually have to have ID export the tagged text files for each. I exported one prototype and copied its tags to properties in my script, and then I concatenate them with the respective list item values I import from the database.
    At the proper point in the page building script, I tell "textwrangleer" to make a new document, set its contents to the index string for the current record, save it to disk, overwriting the previous one, and then tell ID to "place" it in the index text frame, which generates the ID index mark.
    I actually got an AS error when I first tried this: "file doesn't exist" or some such. Then I realized that the "place" command was happening too soon, so I inserted a .5 sec delay in the script, and it worked.
    This is actually my first major script for actual work, and I'm so excited about it! I promises to cut production time down to about a thenth of what it was.
    I still have to add some logic to branch between handlers with slightly different parameters for five different page formats, but the same page building handler will work on all of them.

    A note on this:
    Daniel Swanson wrote:
    I've tried various js scripts which do an OK job, but they don't make the actual native markers. This means you have to wait until the book (consistiing of multiple ID files) is complete (so that all the page numbers have been established) to generate the index.
    These scripts typically search for words and immediately write out the page numbers they are found on -- one shot indexing.
    The solution is to add both the topic and its page reference to the current document's index:
    if (app.activeDocument.indexes.length == 0)
        app.activeDocument.indexes.add();
    app.activeDocument.indexes[0].topics.add(app.selection[0].contents).pageReferences.add(app.selection[0]);
    The first lines only make sure there is an index to add to (per default, a new document has none).
    The last line adds a selected word to the index (it must be a plain text string, hence the use of its 'contents'), and then adds a reference to the selection in the text itself.
    Adding the same word a second time will for a change (quite untypically for ID's Scripting) not result in an error but simply add another page reference to the existing one.
    When doing this in a loop: remember to work backwards, because the index marker itself gets inserted into the running text, and that will throw off your text indices.

  • Select by Note using Applescript

    I want to know if it's possible using Applescript to select items based on the contents of the Note field of the Attibutes Panel. It's used to select objects within Actions, so it seems like it should be possible.
    Unfortunately I'm not very good at scripting and can't seem to figure out the right syntax.
    Thanks in advance for any ideas or suggestions...
    Mike D.

    Hey, Mike:
    Yes, it's possible to select an item based on the contents of its Note.
    every page item whose note contains "testing" -- This would return a list of page items who has "testing" in the note. This includes an item with the word "retesting" so remember to be specific. These are only computers after all… they're not very smart! ;^)
    This is doable but remember you can name any and all items on a page and select them based on that parameter. Unless you have a particular reason to use the Note property I would use Name but either way can be worked out.
    Cheers,
    storm371

  • How to: Close "Getting Playlist" using applescript ?

    Hi *,
    How is it possible to close the iTunes "Getting Playlist" Pop-up window using applescript ?
    Take a look at --> http://www.cronomik.org/t1.jpg
    I have tried to do the following, but iTunes doesn't act.
    tell application "System Events"
    tell application "iTunes" to key code 53
    end tell
    Any ideas of how to fix my question ?
    Stefan

    I have got it working with this script.
    If iTunes Pop-up a message, I press a key on my remote control and the Pop-up message / Box disappears.
    tell application "System Events"
    tell process "iTunes"
    -- get the front window's name
    -- get the name of the front window
    set whichWindow to (get the name of the front window)
    -- Ergebnis: "Getting Playlist"
    -- display dialog result
    -- display dialog whichWindow
    -- Ergebnis: {button returned:"OK"}
    set whichButton to (get the name of the front window's button)
    -- Ergebnis: {"Stop"}
    tell whichButton of window whichWindow to key code 53
    -- set the contents of the button to key code 53
    end tell
    end tell
    In a terminal I have typed in "while true; do ./diut.app; sleep 2; done" to see what happend, if iTunes is front most and an iTunes message Pop-up.
    Solved by myself.

  • Using AppleScript to create folders and place files in them

    Hi guys,
    I've been reading through the forum for the better part of the last 6 hours wracking my brain trying to figure out how to accomplish what I'm trying to do. I've been playing around with Automator and also trying to decipher some Apple Script samples that were posted on here, but I'm really having no luck at all. I'm sure you've all been there where you feel like you're on an endless search to solve a problem and it feels like there's no hope. I've tried every single possible thing I can and I'm getting close, but it's never quite right.
    Here's what I'm trying to do, and hopefully some kind soul will help me out. I'm deseperately trying to figure this out, and any help at all would be GREATLY appreciated!
    I have a bunch of PDF files that I scan, in the hundreds. After I've scanned them I'm left with something like this:
    1234567_Elephant.pdf
    1234567_Duck.pdf
    1234567_Cat.pdf
    1234567_Cat_01.pdf
    1234567_Dog.pdf
    3431233_Elephant.pdf
    3431233_Dog.pdf
    3431233_Dog_01.pdf
    3431233_Duck.pdf
    etc...
    So they have a 7 digit ID, then the file name which is always one of the 4 options (I'm just using the animals as examples, but they would be other words).
    What I'd want the script to do is categorize these into folders based on the ID number, and then based on the "animal" and then the files within them. Note, some files have an _01 or _02 etc... appended to them. I don't know if this makes a difference.
    So after running the script I'd love to see
    1234567 (Folder)
         Elephant (Subfolder)
              1234567_Elephant.pdf (File)
         Duck (Subfolder)
              1234567_Duck.pdf (File)
         Cat (Subfolder)
              1234567_Cat.pdf (File)
              1234567_Cat_01.pdf (File)
         Dog (Subfolder)
              1234567_Dog.pdf (File)
    3431233
         Elephant
              3431233_Elephant.pdf
         Dog
              3431233_Dog.pdf
              3431233_Dog_01.pdf
         Duck
              3431233_Duck.pdf

    well, using a couple of stock handlers I had lying around, and making the following assumptions:
    that an underscore is always the delimiter used
    that the file name is always a single word like 'dog' or 'cat' (if you have multiple word file names, the script needs to be modified some)
    this should do what you ask:
    set mainFolder to (choose folder) as text
    tell application "System Events"
      -- get all the unsorted files, and loop through
              set unsortedFiles to every file of folder mainFolder whose visible is true
              repeat with thisFile in unsortedFiles
      -- split the file name on underscores and periods
                        set fileNameBits to my tid(name of thisFile, {"_", "."})
      -- first item of list is id, make/get correct folder
                        set IDFolder to my checkForFolder(mainFolder, item 1 of fileNameBits)
      -- second item of list is file name, make/get correct folder in id folder
                        set groupFolder to my checkForFolder(IDFolder, item 2 of fileNameBits)
      -- move file
      move thisFile to groupFolder
              end repeat
    end tell
    to checkForFolder(fParent, fName)
      -- subroutine checks for folder, creating it if it doesn't exist
              tell application "System Events"
                        if not (exists folder fName of folder fParent) then
                                  set output to path of (make new folder at end of folder fParent with properties {name:fName})
                        else
                                  set output to (path of (folder fName of folder fParent))
                        end if
              end tell
              return output
    end checkForFolder
    on tid(input, delim)
      -- subroutine for handling text item delimiters
              set {oldTID, my text item delimiters} to {my text item delimiters, delim}
              if class of input is list then
                        set output to input as text
              else
                        set output to text items of input
              end if
              set my text item delimiters to oldTID
              return output
    end tid

  • Using applescript to open "any" images in an specified application?

    I want to use applescript as part of a workflow in Automoator.
    Automator already takes care of the renaming and resizing of my pics.
    Then I want applescript to take each pic that I throw at it and apply it to an image optimizer application I have.
    I've looked all over gooel and I can' find anything.
    Everyscript I see has a specific file name or folder.
    I want applescipt to take a file with any name and launch "ImageOptim" and open the file with ImageOptim.
    This app is a drag and drop app, just drop your pictures on the window or on the icon and it'll optimize your pics on the spot. It doesn't create a new file, the file itself is changed.
    And that's it.
    I had this but it doens't work
    set this_file to choose file without invisibles
    try
              tell application "Finder"
      activate
                        open application file "ImageOptim.app" of folder "Applications" of startup disk
                        set this_image to open this_file
              end tell
    end try
    Thanks for the help.

    Red's already shown you one solution, but your script has multiple errors and it's worth clarifying them
    set this_file to choose file without invisibles
    OK, nothing wrong with this line
              tell application "Finder"
      activate
    There's no need to activate the Finder to perform this task. The Finder's quite happy to run in the background.
                        open application file "ImageOptim.app" of folder "Applications" of startup disk
    This opens the application.
                        set this_image to open this_file
    This would open this_file - except that this command is completely independent and disconnected from the previous command - in other words you're just telling the Finder to open the file, it doesn't care about what other commands you might have asked it to run previously.
    The solution is to tell the Finder to open the file using the specific application you want.
    Another option may be to eschew the Finder altogether, and just tell the app to open the file:
    set this_file to choose file without invisibles
    tell application "ImageOptim" to open this_file

  • How to gather Calendar events using applescript?

    How do you gather any events schedualed for that day on calendar by using applescript?

    I have got it working with this script.
    If iTunes Pop-up a message, I press a key on my remote control and the Pop-up message / Box disappears.
    tell application "System Events"
    tell process "iTunes"
    -- get the front window's name
    -- get the name of the front window
    set whichWindow to (get the name of the front window)
    -- Ergebnis: "Getting Playlist"
    -- display dialog result
    -- display dialog whichWindow
    -- Ergebnis: {button returned:"OK"}
    set whichButton to (get the name of the front window's button)
    -- Ergebnis: {"Stop"}
    tell whichButton of window whichWindow to key code 53
    -- set the contents of the button to key code 53
    end tell
    end tell
    In a terminal I have typed in "while true; do ./diut.app; sleep 2; done" to see what happend, if iTunes is front most and an iTunes message Pop-up.
    Solved by myself.

  • AppleScript: Set folder name of Folder Action?

    Problem:
    How to get the folder name that the running Folder Action script is attached too. Script is functional, stdin bash script with AppleScript via osascript. I just want the folder name, not the POSIX path to it. The System Events dictionary suggests this is possible. I don't want to hardcode the action's assigned folder in the bash script if I can get it dynamically from AppleScript. I know how to return it to bash. AppleScript newbie that has spent several hours googling and testing already.
    Tried:
    tell application "Finder"
         --AppleScript Editor can't get container -- no surprise. Folder action does work
         get POSIX path of (container of ((path to me) as text))
         set workingDir to quoted form of result
         display alert "Current Folder: " message workingDir as critical
    end tell
    tell application "System Events"
         activate
         --AppleScript Editor can't get name of folder action. Folder action does not work
         set currentDir to name of folder action
    end tell
    Appreciation for time and solution in advance.

    twtwtw wrote:
    In that case I suggest you make your life easier.  delete the osascript bit and just return a 0 or 1 from the shell script.  That integer will be passed on to the next action, so add an applescript action that checks to see if the input is 0 or 1 and displays a dialog if necessary:
    on run {input, parameters}
              if input as integer > 0 then
      -- error
      display alert "whatever"
              end if
    end run
    The only reason I posted in the first place was to assess if it was possible to dynamically discover the folder name of the folder action using AppleScript through an osascript request. If the bash script has to be scrapped and entirely rewritten as a Applescript action -- just to obtain the folder name, then that answers my question.
    The purpose of the osascript was to provide an OS X style, user friendly dialog that displays any martian files the bash script ignored. It was the least amount of coding for the result.
    I believe that your input example from above would take the exit status from the preceding shell script. How is my invalidFiles variable passed then? In the shell script, I can pipe the invalidFiles printf line to pbcopy to put that content on the clipboard. After the script is done, I can retrieve that information with a pbpaste command. I wonder if this information is available to your trailing AppleScript action for inclusion in the display alert statement?

  • Can I chart in Numbers using AppleScript

    I have just started learning AppleScript so that I can automate some business processes and save myself some time. Because of better design and ease of use I use the latest version of iWork and don't even have Office installed on my Mac, nor do I want to install it. However, one area I cannot work out is how to automate the creation of a chart in Numbers using AppleScript.
    Is this possible? If so, how, and if not, why not?

    Answering questions like : how may we do this or that, is what we are supposed to try to achieve in this forum.
    Answering questions like yours : why this or that, can't be seriously done here.
    Here you ask to end users like you. We don't belong to the teams designing the apps.
    We just may try to guess.
    To build tables and charts Pages and Numbers share the same pieces of code so there is no technical reasons able to explain the omission.
    So I guess that, as Pages is in its 4th version, designers had more time available to embed features in the AppleScript support than those working upon Numbers.
    What's funny is that there is a minimal support for charts in Pages (as well as a microscopic support for tables) but there is a correct support for tables (which may be enhanced) in Numbers but nothing for charts.
    Honestly, I really don't think that the difference is huge.
    I posted my script too fast.
    I forgot to insert the handler allowing us to bring a sheet at front which is required to apply GUIScripting.
    It's probably the main drawback of the need to use GUIScripting here.
    I don't waste time trying to apply some edit tasks to the charts.
    I just wanted to fill the gap between Pages and Numbers about scripting charts.
    Here is an enhanced version.
    --{code}
    --[SCRIPT add_charts]
    Yvan KOENIG (VALLAURIS, France)
    2011/08/27
    on run
              my activateGUIscripting()
              tell application "Numbers" to tell document 1
                        set dName to its name
                        set sName1 to name of sheet 1
                        set sName2 to name of sheet 2
    Select sheet 1 of document 1
    The doc name may be passed by a number but the sheet must be identified by its name .
    As it's just a sample, in the first call I reference the doc by its index *)
                        my selectSheet(1, sName1)
                        tell sheet sName1 to tell table 1
    Always define the selection before creating a chart *)
                                  set selection range to range (name of cell 4 of column 2 & " : " & name of cell 8 of column 3)
                                  my selectSubMenu("Numbers", 5, 4, 9) -- Scatter chart
    Always define the selection before creating a chart *)
                                  set selection range to range (name of cell 4 of column 2 & " : " & name of cell 8 of column 3)
                                  my selectSubMenu("Numbers", 5, 4, 3) -- Bars
    Always define the selection before creating a chart *)
                                  set selection range to range (name of cell 4 of column 2 & " : " & name of cell 8 of column 3)
                                  my selectSubMenu("Numbers", 5, 4, 4) -- Stacked Bars
    Always define the selection before creating a chart *)
                                  set selection range to range (name of cell 4 of column 3 & " : " & name of cell 8 of column 3)
                                  my selectSubMenu("Numbers", 5, 4, 20) -- 3D Pie
                        end tell
    Select sheet 2 of document 1
    This time, I reference the document by its name *)
                        my selectSheet(dName, sName2)
                        tell sheet sName2 to tell table 1
    Always define the selection before creating a chart *)
                                  set selection range to range (name of cell 4 of column 2 & " : " & name of cell 8 of column 3)
                                  my selectSubMenu("Numbers", 5, 4, 9) -- Scatter chart
    Always define the selection before creating a chart *)
                                  set selection range to range (name of cell 4 of column 2 & " : " & name of cell 8 of column 3)
                                  my selectSubMenu("Numbers", 5, 4, 3) -- Bars
    Always define the selection before creating a chart *)
                                  set selection range to range (name of cell 4 of column 2 & " : " & name of cell 8 of column 3)
                                  my selectSubMenu("Numbers", 5, 4, 4) -- Stacked Bars
    Always define the selection before creating a chart *)
                                  set selection range to range (name of cell 4 of column 3 & " : " & name of cell 8 of column 3)
                                  my selectSubMenu("Numbers", 5, 4, 20) -- 3D Pie
                        end tell --sheet 2…
              end tell -- Numbers…
    end run
    --=====
    on parleAnglais()
              local z
              try
                        tell application "Numbers" to set z to localized string "Cancel"
              on error
                        set z to "Cancel"
              end try
              return (z is not "Annuler")
    end parleAnglais
    --=====
    on activateGUIscripting()
      (* to be sure than GUI scripting will be active *)
              tell application "System Events"
                        if not (UI elements enabled) then set (UI elements enabled) to true
              end tell
    end activateGUIscripting
    --=====
    ==== Uses GUIscripting ====
    on selectSheet(theDoc, theSheet)
              script myScript
                        property listeObjets : {}
                        local maybe, targetSheetRow
                        tell application "Numbers"
      activate
                                  set theDoc to name of document theDoc (* useful if the passed value is a number *)
                                  tell document theDoc to set my listeObjets to name of sheets
                        end tell -- "Numbers"…
                        set maybe to theSheet is in my listeObjets
                        set my listeObjets to {} -- So it will not be saved in the script *)
                        if not maybe then
                                  if my parleAnglais() then
                                            error "The sheet “" & theSheet & "” is unavailable in the spreadsheet “" & theDoc & "” !"
                                  else
                                            error "La feuille « " & theSheet & " » n’existe pas dans le tableur « " & theDoc & " » ! "
                                  end if -- my parleAnglais
                        end if -- not maybe
                        set maybe to 5 > (system attribute "sys2")
                        tell application "System Events" to tell application process "Numbers"
                                  tell outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window theDoc
                                            if maybe then (* macOS X 10.4.x
    '(value of attributes contains 0)': '(value of attribute "AXDisclosureLevel" is 0)' sometimes works in Tiger, sometimes not.
    The only possible instances of 0 amongst the attributes are the disclosure level of a sheet row and the index of the first row, which represents a sheet anyway.
    Another possibility is '(value of attribute -1 is 0)', which makes me uneasy. *)
                                                      set targetSheetRow to first row where ((value of attributes contains 0) and (value of first static text is theSheet))
                                            else (* macOS X 10.5.x or higher *)
                                                      set targetSheetRow to first row where ((value of attribute "AXDisclosureLevel" is 0) and ((groups is {}) and (value of first static text is theSheet)) or (value of first group's first static text is theSheet))
                                            end if -- maybe…
    Handler modified to accomodate sheets requiring a lot of time to get the focus
                                            tell targetSheetRow to set value of attribute "AXSelected" to true
                                            set cnt to 0
                                            repeat (*
    Must way that Numbers becomes ready to receive the value *)
                                                      try
                                                                tell targetSheetRow to set value of attribute "AXDisclosing" to true
                                                                exit repeat
                                                      on error
                                                                set cnt to cnt + 1
      delay 0.5 -- half a second
                                                      end try
                                            end repeat
                                  end tell -- outline…
                        end tell -- "System Events"…
                        tell application "Numbers" to tell document theDoc to tell sheet theSheet to tell table 1
                                  with timeout of 20 * 60 seconds (*
    WITH this setting, the script will be able to wait 20 minutes for the asked value.
    I hope that the document will not be so huge that this delay prove to be too short. *)
                                            value of cell "A1"
                                  end timeout
                        end tell -- "Numbers"…
                        tell application "System Events" to tell application process "Numbers" (*
    Do the trick one more time to be sure that the sheet is open *)
                                  tell targetSheetRow to set value of attribute "AXDisclosing" to true
                        end tell -- "System Events"…
    End of the modified piece of code
              end script
      run myScript
    end selectSheet
    --=====
    my selectSubMenu("Pages",6, 4, 26)
    ==== Uses GUIscripting ====
    on selectSubMenu(theApp, mt, mi, ms)
              tell application theApp
      activate
                        tell application "System Events" to tell process theApp to tell menu bar 1 to ¬
                                  tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1 to click menu item ms
              end tell -- application theApp
    end selectSubMenu
    --=====
    useful to get the indexs of the triggered item
    my select_SubMenu("Numbers", 6, 4, 3) (* Table > Chart> Bars *)
    on select_SubMenu(theApp, mt, mi, ms)
              tell application theApp
      activate
                        tell application "System Events" to tell process theApp to tell menu bar 1
                                  get name of menu bar items
    01 - "Apple",
    02 - "Numbers",
    03 - "Fichier",
    04 - "Édition",
    05 - "Insertion",
    06 - "Tableau",
    07 - "Format",
    08 - "Disposition",
    09 - "Présentation",
    10 - "Fenêtre",
    11 - "Partage",
    12 - "Aide"}
                                  get name of menu bar item mt
      -- {"Tableau"}
                                  tell menu bar item mt to tell menu 1
                                            get name of menu items
    01 - "Feuille",
    02 -  missing value,
    03 - "Tableau",
    04 - "Graphique",
    05 - "Figure",
    06 - "Zone de texte",
    07 - "Fonction",
    08 - "Ligne de connexion",
    09 - missing value,
    10 - "Remplissage",
    11 - missing value,
    12 - "Rangs copiés",
    13 - "Colonnes copiées",
    14 - missing value,
    15 - "Date et heure",
    16 - "Nom du fichier",
    17 - "Numéro de page",
    18 - "Nombre de pages",
    19 - missing value,
    20 - "Commentaire",
    21 - "Lien",
    22 - "Saut de colonne",
    23 - "Équation MathType",
    24 - missing value,
    25 - "Choisir…"}
                                            get name of menu item mi
      --> "Graphique"
                                            tell menu item mi to tell menu 1
                                                      get name of menu items
    01 - "Colonnes",
    02 - "Colonnes empilées",
    03 - "Barres",
    04 - "Barres empilées",
    05 - "Ligne",
    06 - "Couches",
    07 - "Couches empilées",
    08 - "Diagramme circulaire",
    09 - "Nuage de points",
    10 - "Mixte",
    11 - "2 axes",
    12 - missing value,
    13 - "Colonnes 3D",
    14 - "Colonnes 3D empilées",
    15 - "Barres 3D",
    16 - "Barres 3D empilées",
    17  - "Linéaire 3D",
    18 - "Couches 3D",
    19 - "Couches 3D empilées",
    20 - "Circulaire 3D"}
                                                      get name of menu item ms
      --> "Barres"
      click menu item ms
                                            end tell
                                  end tell
                        end tell
              end tell -- application theApp
    end select_SubMenu
    --=====
    --[/SCRIPT]
    --{code}
    Yvan KOENIG (VALLAURIS, France) samedi 27 août 2011 15:19:15
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • Using AppleScript to Launch Excel VBA Macro

    Using MS Office 2004 and AppleScript 1.9.3. I want to use AppleScript in MS Entourage to kick off a VBA macro in Excel. But no luck.
    To test things, I created an Excel file ("test.xls") with a one-line VBA macro named "test." It just puts up a dialog box with the message "success." I'm calling it from A.S as follows (per the AppleScript Dictionary for Excel 2004):
    tell application "Microsoft Excel"
    run VB macro "hard disk:users:xxx:desktop:test.xls!test"
    end tell
    I get two successive error messages:
    1. 'test.xls' cannot be accessed. The file may be read-only or you may be trying to access a read-only location."
    2. "Microsoft Excel got an error: "hard disk:users:xxx:desktop:test.xls!test" doesn't understand the run VB macro message."
    "test" file permissions are -rw-r--r-- and it is sitting right on the desktop.
    FWIW, I did not remove the old Office vX yet, but renamed old Excel "Microsoft ExcelOld". I read on some other site that this may cause problems.
    This has been endlessly frustrating. HELP!!??
    Steve

    Hi Steve,
    Have you tried dealing with the return value from your macro? If you are invoking the MsgBox function in your test macro, you may need to allow the return value from MsgBox to pass thru back to AS. Something like :
    set MyRetCode to run VB macro "Macintosh HD:Users:xxx:Desktop:test.xls!test"
    (Note unless you've changed the hard drive name to "hard drive", the default boot drive name will probably be "Macintosh HD". Case does matter here)
    I also suspect you'll need to have Entourage up as well in the full case of running a macro in Entourage from Excel (or the other way around). Hence, the command ActivateMicrosoftApp in the Excel dictionary may also be useful.
    Second, you can have a macro, in a startup template, in Entourage call a macro in a startup template in Excel to accomplish what you want without going into AppleScript at all. This latter, VB-only, method will require a "Reference", as it's called in VBA, to be added to the TemplateProject in Entourage that points to the Excel macro you want to fire off. The added benefit of this latter method is that you will have access to the full range of VBA commands/options, rather than the smaller dictionary available in AS.
    Ed
    PB G4   Mac OS X (10.2.x)  

  • New to applescript. need to create a plist file using applescript

    Needed some help I need on creatinga plist file below using applescript and I can't make it happen needed some hand on this.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Username</key>
    <string>${localAdminUser}</string>
    <key>Password</key>
    <string>${localAdminPassword}</string>
    <key>AdditionalUsers</key>
    <array>
    <dict>
    <key>Username</key>
    <string>${userName}</string>
    <key>Password</key>
    <string>${userPassword}</string>
    </dict>
    </array>
    </dict>
    </plist>
    I have tis code but it doesn't seems to work.
    tell application "System Events"
      -- create an empty property list dictionary item
              set the parent_dictionary to make new property list item with properties {kind:record}
      -- create new property list file using the empty dictionary list item as contents
              set the plistfile_path to "~/Desktop/example.plist"
              set this_plistfile to ¬
      make new property list file with properties {contents:parent_dictionary, name:plistfile_path}
      -- add new property list items of each of the supported types
      make new property list item at end of property list items of contents of this_plistfile ¬
                        with properties {kind:string, name:"Username", value:"${localAdminUser}"}
      make new property list item at end of property list items of contents of this_plistfile ¬
                        with properties {kind:string, name:"Password", value:"${localAdminPassword}"}
      make new property list item at end of property list items of contents of this_plistfile ¬
                        with properties {kind:list, name:"AdditionalUsers"}
      make new property list item at end of property list items of contents of this_plistfile ¬
                        with properties {kind:string, name:"Username", value:"${localAdminUser}"}
      make new property list item at end of property list items of contents of this_plistfile ¬
                        with properties {kind:string, name:"Password", value:"${localAdminPassword}"}
    end tell
    The result of the above code will generate a plist file below
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
              <key>AdditionalUsers</key>
              <array/>
              <key>Password</key>
              <string>${localAdminPassword}</string>
              <key>Username</key>
              <string>${localAdminUser}</string>
    </dict>
    </plist>

    Hello
    You need to create elements at correct container. Like this.
    set plist_file to (path to desktop)'s POSIX path & "example.plist"
    --set plist_file to "~/desktop/example.plist"
    tell application "System Events"
        tell (make new property list file with properties {name:plist_file})
            make new property list item at end with properties {kind:string, name:"Username", value:"${localAdminUser}"}
            make new property list item at end with properties {kind:string, name:"Password", value:"${localAdminPassword}"}
            tell (make new property list item at end with properties {kind:list, name:"AdditionalUsers"})
                tell (make new property list item at end with properties {kind:record})
                    make new property list item at end with properties {kind:string, name:"Username", value:"${localAdminUser}"}
                    make new property list item at end with properties {kind:string, name:"Password", value:"${localAdminPassword}"}
                end tell
            end tell
        end tell
    end tell
    Or you may create a record in AppleScript and set the value of plist file at once. Like this.
    set plist_file to (path to desktop)'s POSIX path & "example.plist"
    --set plist_file to "~/desktop/example.plist"
    set dict to ¬
        {|Username|:"${localAdminUser}", |Password|:"${localAdminPassword}"} & ¬
        {|AdditionalUsers|:{¬
            {|Username|:"${localAdminUser}", |Password|:"${localAdminPassword}"} ¬
    --set dict to {|Username|:"${localAdminUser}", |Password|:"${localAdminPassword}", |AdditionalUsers|:{{|Username|:"${localAdminUser}", |Password|:"${localAdminPassword}"}}}
    tell application "System Events"
        tell (make new property list file with properties {name:plist_file})
            set value to dict
        end tell
    end tell
    Regards,
    H
    Message was edited by: Hiroto (PS. Fixed second script so that it uses the original case (uppercase)  in key string)

  • ICal and subscribed calendars with MobileMe using AppleScript

    I am having the same problem as many of you; I have a MobileMe account which does not sync the calendars I have in iCal that are subscriptions. I found this great script online which I'll post below. I don't know anything about AppleScript so I'm just copy-pasting. I want it to work, but I'm getting the error "The variable theOldEvent is not defined." right around the line "if similar_found is true then set theOldSummary to the summary of theOldEvent" kinda near the middle. Like I said, I don't know anything about AppleScript. So my question is; how can I fix this error and/or is there some better way of using AppleScript/Automator to do this same thing? Thanks!
    Script to duplicate Calendar orgCalendar into target dupCalendar
    E.H. 12.9.2008
    property myCopies : 0
    property myUpdates : 0
    property myObsoletes : 0
    property orgCalendar : "Sekretariat"
    property dupCalendar : "Sekretariat copy"
    property dupEvents : {}
    property myDeletes : {}
    set myCopies to 0
    set myUpdates to 0
    set myObsoletes to 0
    set dupEvents to {}
    tell application "iCal"
    -- set theCalendars to every calendar
    set theCalendarNames to title of every calendar
    set theOrgCalendar to a reference to calendar orgCalendar
    if theCalendarNames contains dupCalendar then
    set theCalendar to a reference to calendar dupCalendar
    else
    set theCalendar to make new calendar with properties {title:dupCalendar}
    --set theCalendar to make new calendar with properties {title:dupCalendar, color:"{65535, 0, 0}"}
    end if
    set the eventList to uid of every event of theOrgCalendar as list
    set the eventCount to the count of the eventList
    repeat with theUId in eventList
    tell theOrgCalendar
    set theEvent to (the first event whose uid is theUId)
    -- set theProperties to the properties of theEvent as record
    set theDate to the start date of theEvent
    set theSummary to the summary of theEvent
    set theStampDate to the stamp date of theEvent
    end tell
    tell theCalendar
    try
    set theOldEvent to (the first event of theCalendar whose (start date) is theDate as date)
    set similar_found to true
    on error
    set similar_found to false
    set theEndDate to the end date of theEvent
    set theAllDay to the allday event of theEvent
    set theLocation to the location of theEvent
    -- Funny construction to work araund the fact that location may be missing a value
    try
    if theLocation is equal to "" then
    end if
    on error
    set theLocation to ""
    end try
    set theDescription to the description of theEvent
    try
    if theDescription is equal to "" then
    end if
    on error
    set theDescription to ""
    end try
    if theAllDay is true then -- work around a funny bug with all day events
    set theDate to (theDate as date) + 2 * hours
    set theEndDate to (theEndDate as date) + 2 * hours
    end if
    set newEvent to make new event at end with properties {summary:theSummary, location:theLocation, start date:theDate, end date:theEndDate, allday event:theAllDay, description:theDescription}
    -- make new event at end with properties theProperties
    set the end of dupEvents to (the uid of newEvent)
    set myCopies to (myCopies + 1)
    end try
    end tell
    set second_necessary to false
    if similar_found is true then
    set theOldSummary to the summary of theOldEvent
    if theSummary is not equal to theOldSummary then
    --is there a different one?
    try
    set theOldEvent1 to (the second event of theCalendar whose (start date) is theDate as date)
    set theOldSummary to the summary of theOldEvent1
    if theSummary is equal to theOldSummary then
    set theOldEvent to theOldEvent1
    set the end of dupEvents to (the uid of theOldEvent)
    else
    -- cycle repeat ?
    end if
    on error
    -- beep
    try
    set theEvent1 to (the second event of theOrgCalendar whose (start date) is theDate as date)
    set second_necessary to true
    on error
    set the end of dupEvents to (the uid of theOldEvent)
    end try
    end try
    else
    set the end of dupEvents to (the uid of theOldEvent)
    end if
    if second_necessary is true then
    set theEndDate to the end date of theEvent
    tell theCalendar
    set theOldEvent to make new event at end with properties {summary:theSummary, start date:theDate, end date:theEndDate}
    end tell
    set the end of dupEvents to (the uid of theOldEvent)
    end if
    set theOldStampDate to the stamp date of theOldEvent
    if theStampDate is greater than theOldStampDate then
    -- update the event
    set summary of theOldEvent to theSummary -- capitalization may have changed
    set theAllDay to the allday event of theEvent
    set allday event of theOldEvent to theAllDay
    set theEndDate to the end date of theEvent
    if theAllDay is true then -- work around a funny bug with all day events
    set theEndDate to (theEndDate as date) + 2 * hours
    end if
    set end date of theOldEvent to theEndDate
    set theDescription to the description of theEvent
    try
    if theDescription is equal to "" then
    end if
    on error
    set theDescription to ""
    end try
    set description of theOldEvent to theDescription
    set myUpdates to myUpdates + 1
    end if
    end if
    end repeat
    end tell
    -- Delete obsolete events
    set myObsoletes to 0
    set myDeletes to {}
    tell application "iCal"
    set myUIDs to uid of events of theCalendar
    end tell
    repeat with myUID in myUIDs
    if dupEvents does not contain myUID then
    set the end of myDeletes to myUID
    set myObsoletes to (myObsoletes + 1)
    end if
    end repeat
    tell application "iCal"
    repeat with myDel in myDeletes
    delete (every event of theCalendar whose uid is myDel)
    end repeat
    end tell
    -- delete duplicates
    set myDeletes to {}
    tell application "iCal"
    set myStarts to start date of events of theCalendar
    set mySummaries to summary of events of theCalendar
    set myUIDs to uid of events of theCalendar
    set myLength to length of myUIDs
    end tell
    repeat with i from 1 to (myLength - 1)
    set thisStart to (item i of myStarts)
    set thisSumm to (item i of mySummaries)
    repeat with j from (i + 1) to myLength
    set thatStart to (item j of myStarts)
    set thatSumm to (item j of mySummaries)
    if thisSumm is equal to thatSumm and thisStart is equal to thatStart then
    set the end of myDeletes to (item j of myUIDs)
    exit repeat
    end if
    end repeat
    end repeat
    set n to count of myDeletes
    tell application "iCal"
    repeat with myDel in myDeletes
    delete (every event of theCalendar whose uid is myDel)
    end repeat
    -- set the visible of calendar theCalendar to false
    end tell
    display dialog (myCopies & " records duplicated, " & myUpdates & " records updated and " & myObsoletes & " obsolete ones deleted") as text

    No longer an issue.

Maybe you are looking for