Automator - applescript

Step1: I wrote an applescript to process an excel file (deleting a few columns and rows).. When I compiled it in Applescript editor, it worked fine.. Gave no errors or warnings..
Step2: I launched Automator. Selected 'Application'. And then selected 'Run Applescript' action. I pasted the same script in the 'Run Applescript' action of automator and when I compiled it, it is giving an error "The result of the numeric operation was too large". I don't know why this happens.. It was working fine before I upgraded to 10.6.2..
Here's the script:
on run {input, parameters}
repeat with eachfile in input
set theWorkbookFile to eachfile
tell application "Microsoft Excel"
open theWorkbookFile
set theWorkbook to active workbook
tell worksheet "Sheet1" of active workbook
delete row 1
delete column 1
repeat with x from 39 to 10 by -1
delete column x
end repeat
end tell
save active workbook
close active workbook saving yes
end tell
end repeat
return input
end run
Since this works fine in applescript, i dont think this would be a problem.. Any help would be highly appreciated..

yes but that's what I'm saying. just do it from applescript.
on open these_items
repeat with eachfile in these_items
set theWorkbookFile to eachfile
tell application "Microsoft Excel"
open theWorkbookFile
set theWorkbook to active workbook
tell worksheet "Sheet1" of active workbook
delete row 1
delete column 1
repeat with x from 39 to 10 by -1
delete column x
end repeat
end tell
save active workbook
close active workbook saving yes
end tell
end repeat
end open
save it as an application from applescript editor and drop as many items as you want at once onto it. it will process them all.

Similar Messages

  • Help Needed: Automator Applescript for Folder Action - Encode Video

    Hi !
    I have created an Automator Applescript for a Folder Action to do the following:
    When a new video file is moved to the target folder (i.e. Download of Vuze is done), automatically launch the Applescript Action that does the followin g(Applescripted):
    1) Using "run shell script" and FFMPEG on a UNIX command line, determine Width/Height, Framerate, Bitrate
    2) Calculate encoding parameters (slightly reduced bitrate, reduced Aspect etc.)
    3) Using "run shell script" with ffmpeg on the command line and the calculated parameters to encode the video file
    At the same time, the action is written to a log file so I know if a file is recognized, when encoding started etc.
    It works fine if I save this Action as an .app, make an alias on the Desktop and drop video files on it.
    It also works fine if I attach the script to a folder as a folder action and drag a video file in there.
    However, when I attach the script as a folder action to the Vuze download folder, it encodes only some video files, i.e. if there was a download of 5 files, chances are good that it will not encode 1 or 2 files out of those 5.
    If for example a second download finishes while the encoding for the first download is still going on, sometimes the second file starts encoding after the first encode finishes, sometimes it does not, the file does not make the log file at all, i.e. the folder action missed it or the automator action dropped it because it was still encoding. Still, sometimes it happens, sometimes not.
    As I need a solution that is 100% accurate, I would like to ask if there are any ideas on how to do this better maybe? As I am not an Applescript Guru, I would need some help to know what works and what doesn't and what the syntax is.
    My main idea right now:
    Similar to how ffmpegX works with its "process" application, have a second script (as .app) that receives the files to be encoded from the automator action and puts them in a queue, then proceeds to encode this queue while the main automator action is free to receive the next file.
    Writing this second app is quite straightforward (a modified version of my current script) but I have some questions I need help with:
    1) How do I call another applescript from within an existing applescript that launches the new applescript in a new process?
    2) How do I pass parameters to this new applescript?
    3) In case of this "Queueing" Idea, once I called the external applescript the first time, how do I make sure when I call next time, that I don't open a second instance of this script but rather pass another queue item to the original instance to be processed?
    Or in general: Is there a better way to achieve this automatic encoding solution that I have not thought about?
    Alternatively:
    Does anyone know how to call the "process" application that comes with the ffmpegX package with the correct parameters to use as a queueing / processing tool?
    Thanks!
    Joe
    Message was edited by: Joe15000
    Message was edited by: Joe15000

    To do this, I created an Automator workflow with an Applescript snippet to change the 'media kind'.
    Here is the 'Run Applescript' workflow step code:
    on run {input, parameters}
              tell application "iTunes"
                        set video kind of (item 1 of input) to movie
              end tell
              return input
    end run
    Prior to this running, I have an 'Import Files into iTunes' workflow step.
    You can switch out 'movie' with: 'TV show', 'music video', or anything in ITLibMediaItemMediaKind.
    Good luck,
    Glenn

  • Need Help with scripting for Automator/AppleScript.

    Hi everybody,
    I am building a small app for my mac, What I need is a script that can rename a file that I drop on it.
    and example being:
    example.jpg
    (when I drop it on the app, I want the app to change the filename of the document to "Image.jpg"
    I have tried this with Automator, but it requires that I specify the file to be changed, what I need is something that will change the name of any file I drag onto it.
    I am using it for application specific files.
    Kind regards,
    Pete.
    iBook G4; 60GB Hard Drive, 512MB RAM, Airport Extreme    

    Open the Script Editor in the
    /Applications/AppleScript/ folder and enter the
    following:
    on open(the_file)
    tell application "Finder"
    set name of the_file to "Image"
    end tell
    end open
    Save this script as an application.
    (11347)
    this script compiled correctly; however when run it returned the following error "Can't set name of (the_file) to "Image.jpg"
    I am also given the option of editing the script or just quitting.
    thanks for your help

  • "batch" exporting to aiff using automator / applescript?

    I often find myself prepping a lot of audio for DV editing in Final Cut Pro....exporting audio out of QT to 48khz, 16bit, aiff.
    I'm looking for a way to do this to many files in 1 step....ie: drag and drop a folder/files onto an icon. Automator doesn't seem to have an export action under quicktime. And all i can do in applescript is tinker, at best.
    I downloaded the QT script package from the apple site.. http://www.apple.com/applescript/quicktime/ these seem like a good start, but im havin trouble tweakin them for .aiff audio
    any suggestions for doing this?

    can do this now with automator

  • Still no Automator / Applescript Support in iWorks 09

    Hi everybody,
    i find it extremly annoying that there are still no iWork Actions in Automator nor is there any native Applescript Support ! Come on Apple, even the bad guys at Microsoft do have Automator actions in their Office 2008 product. I bought iWork 08 i will not buy iWork 09. Am i the only person who would like to have support for automator and applescript build into the products ?
    cheers
    Ronny

    No, M$ feels they have to lead you by the hand. Apple knows there users are brighter and can do many things themselves.
    What are they going to make? How do they know what automator actions will be needed by the community until the scripting is out and available, And they see how we end up using the technology.
    Perfect example, they didn't introduce all 350+ functions available in XL in the numbers 1.0 version. They released about 150, then listened to the community to see what we wanted most. THEN they let their engineers go on those points, not WASTING their time and money creating stuff that nobody needs, or only 5% need. Now we have ~100 more functions, and even a new data type, duration, that XL doesn't have. why? because many people were trying to use Numbers to keep track of things like blood pressure logs, jogging logs, etc...
    Another real world example, college campus', Believe it or not the best designers of campuses do not put sidewalks in except for around the buildings themselves, not between them. Because they cannot predict what class patterns the students will end up having, or what habits they, as a group, will develop. They wait till about a year later, see where the grass has been worn down to paths and make sidewalks over those paths.
    This is classic design paradigms when you have a random, unpredictable user base that could require almost anything from you. Let them start by designing to fit their needs, then make official releases that take those concepts one step further and completely debugged and up to your standards.
    Just my second set of two cents,
    Jason

  • Automator/AppleScript for adding code to an html file

    Hi all,
    I have a bunch of files (60+) that have been converted from xml to html so that they can be read by the calibre eBook software. Because they were originally .xml files, they do not have opening or closing htiml or body tags. They won't open in Word, only textedit. I am looking for a way to insert the <html> <body> and </body> </html> codes into each file as quickly/painlessly as possible, ideally as a workflow, or series of workflows, that I could use later with other files of this type.
    Can anyone advise me on how to do this? I'm new at coding/applescript/automator, but I'm generally a quick study.

    This is an applescript version which should be a little more comprehensible.
    -- select files - might be easier ways to do this depending on your setup
    set fileList to choose file with prompt "Choose files to wrap in HTML tags" with multiple selections allowed
    -- loop through files
    repeat with thisFile in fileList
      -- open the file for writing
              set fp to open for access thisFile with write permission
      -- grab contents of file and wrap it in tags
              set unmodifiedText to read fp
              set modifiedText to "<html>" & return & "<body>" & return & unmodifiedText & return & "</body>" & return & "</html>"
      -- write the new text out to the file and close it.
              set eof of fp to 0
              write modifiedText to fp
              close access fp
    end repeat

  • Use Automator/AppleScript to clean iPhoto Library

    Hello,
    Having read a lot of posts about the use of AppleScript and Automator to do things with iPhoto, I think it's possible to create a script or a processus to clean the iPhoto Library (let say, a copy of it) to eliminate "zombie files" (photos which have not been deleted of the iPhoto Library when emptying the iPhoto trash).
    The script should simply verify, for each file in the "master" folder, il the path of this file is known in the iPhoto database (the data base is in the "AlbumData.xml" file). If it is, the file is kept. It it's not, the file is moved to trash (or to a temporary folder).
    Should anyone create this script ? I should try, but I would need two weeks to do it correctly, and I'm sure someone can do it in 5 minutes... Some help here ? Thanks !

    Hi,
    Try this AppleScript:
    repeat
        set r to (choose file with prompt "Select an iPhoto Library package" default location (path to pictures folder)) as string
        try
            (r & "AlbumData.xml") as alias
            (r & "Masters") as alias
            (r & "Previews") as alias
            exit repeat
        on error
            activate
            display dialog "This package does not contains \"AlbumData.xml\" file or the \"Masters\" folder or the \"Previews\" folder." buttons {"OK"} default button "OK"
        end try
    end repeat
    set iPhoto_Library to quoted form of POSIX path of r
    set AlbDataXML to quoted form of POSIX path of (r & "AlbumData.xml")
    tell application "Finder"
        set newFolder to (make new folder) as string
        set dest to (make new folder at folder newFolder with properties {name:"Images qui ne sont pas dans AlbumDataXML"}) as string
    end tell
    set destF to quoted form of POSIX path of dest
    set file1 to quoted form of POSIX path of (newFolder & "filesPath.txt")
    set file2 to quoted form of POSIX path of (newFolder & "PhotosDataPath.txt")
    do shell script "dest=" & destF & "; tFile=" & file1 & "; tFile2=" & file2 & "; iPhotoLib=" & iPhoto_Library & ";
    grep -A1 '\\(\\<key>OriginalPath<\\|\\<key>ImagePath<\\)' " & AlbDataXML & "  | sed -n  '/<string>/s/^.*<string>\\(.*\\)<\\/string>$/\\1/p' | sort -o \"$tFile2\"
    find \"$iPhotoLib\"Masters -type f \\! -name '.*' >\"$tFile\"
    find \"$iPhotoLib\"Previews -type f \\! -name '.*' >>\"$tFile\"
    sort -o \"$tFile\" \"$tFile\"
    diff -ab  \"$tFile2\" \"$tFile\" | sed -n '/> /s/^> //p' | while read f; do
       name=${f##*/}
       if [ -e \"$dest$name\" ];then
            i=1
            while [ -e \"$dest$name $i\" ];do
                ((i++))
            done
            name=\"$name $i\"
       fi
       /bin/mv -f \"$f\" \"$dest$name\"
    done"
    tell application "Finder"
        activate
        reveal folder dest -- select the folder which contains moved files
    end tell
    This script move every files in the ("Masters" and "Previews") folders which it's path is not in the "AlbumData.xml" file to a new folder on the desktop.
    The grep command get all path in "AlbumData.xml" from the (OriginalPath and ImagePath) keys and put the result in file2.
    The find command get all file's path in the ("Masters" and "Previews") folders and put the result in file1.
    The diff and sed command get all file path in text file1 which is not in text file2
    Before moving file:
    This script check name of the file to not overwrite any file in the destination folder.
    If a name already exist in the destination folder, the script add a space and a number to the end of the filename.

  • Automator/Applescript action to redirect selected messages individually?

    I have been studying Automator to see if I could create a workflow that takes all currently selected messages and sends them one by one to a fixed e-mail address. I want to use this to select junk mail and send them to the junk mail trainer address. Nothing more than for each message a Cmd-E, type-junk-mail-trainer-address, Cmd-D.
    I haven't been able to find out (I spent maybe one to two hours on this) to get even one thing working. Now, before I go in deep and try to learn AppleScript, is there may be some beast already out there?
    Thanks,
    G

    After having looked on the internet (Google, mainly and clicking through) I have concluded that as far as people have tried this they have failed because Mail's redirect AppleScript command is broken (at least until 10.4.6). Discussions go on at depth regarding debugging this broken stuff.
    I have also not found any usable script.
    So, my conclusion is that this very handy tool that would work fine with Mac OS X Server's junkmail/notjunkmail trainer addresses for spam is currently not possible. Maybe something for Apple to provide in mail (train/untrain mail server command)

  • Automator/Applescript error for Library selection - workarounds ?

    I am creating some Automator actions to simplfy my workflow, but do it in a way that suits me. eg.
    Step 1. Copy CF images to Time Capsule (easy)
    Step 2. Import CF images into Aperture doing the following:
    a. Import with option to create a new project (non-refd)
    b. Set ratings to 1.
    c. Set some IPTC data.
    d. Select some basic keywording
    Bang ! - import it all
    Seems and is reasonably easy, however two observations in the import to Aperture execution:
    - It runs very slowly (i might be able to live with this)
    - I often get an Applescript error and it seems linked to this old Apple doc asking me to add a 'Set Aperture Library" step in the Applescript ?! Huh ?
    http://docs.info.apple.com/article.html?artnum=307040
    Currently triggering both actions as Applications, but hope to sequentiall link them if i can get the solve for the error.
    Q1. Can i 'fix' this error within Automator actions ?
    Q2. Is it normal for the set rating and IPTC tagging to be glacial slow ?
    Getting more impressed with Automator power, but it sometimes seems to be a little flakey (perhaps or its me!)
    Appreciate any pointers...

    Scripts currently run v. slowly if you have a large library... submit a bug using the feedback form!

  • Automator-Applescript Problem

    I have got an Automator problem that is down mainly to Applescript (I believe) that is posted in the Automator category: http://discussions.apple.com/thread.jspa?threadID=1896508&tstart=0 . Please help, I really need an answer before midnight GMT.

    Actions return their results in a list, so even though you are setting the input to "Stop", what the next action is getting is {"Stop"}. In your Run AppleScript action, you will need to look for your item in the input list - for example:
    if the input contains "Stop" then
          -- or --
    if the first item of the input is "Stop" then

  • Automator Applescript Service Workflow

    I have created a few Service workflows using Automator, but one in particular is giving me a hard time. I stop a process with one script using "do shell script" and "with administrator privileges" and everything runs fine. When I run the workflow from the services commands to start the process again, it starts, but I end up with the spinning gear in the menu bar as though the script has not finished. Does anybody know if this is a bug in automator/scriptable services menu or is this a bug in applescript? Again, this doesn't happen when I stop the process, only when I staRT IT UP AGAIN.

    please provide more details. it's impossible to say anything meaningful based the info provided. full details of the workflow would be nice.

  • Automator/Applescript for Pages

    Does anyone know of a good reference for Automator Actions or Applescripts for Pages? I've looked at all the usual websites and no one has any. All I'm trying to do is use a script to automate the process of opening Word docs and save them as Pages files.

    I do not think there is anything really well written and exhaustive on the matter. I have three main sources:
    1. Pages script dictionary (available in ScriptEditor through Open Dictionary > Pages).
    2. This page with a script that goes the opposite way: http://pagesfaq.blogspot.com/2006/11/i-have-one-thousand-pages-documents-to.html
    3. Searching Google for the string "tell application Pages".

  • Automator/Applescript to Create New Pages Doc in Selected Folder

    When working in Finder I'd like to be able to create a folder, and then (still within Finder) create a number of Pages documents inside that folder. This would help in organizing complex projects, and would be preferable to creating the documents (from the bottom up) in Pages and then laboriously assigning each document to a different folder.
    I've tried various solutions in Automator and Applescript but nothing has worked.
    For example:
    try
    tell application "finder" to set myFolder to (folder of the front window)
    on error -- no open folder windows
    set myFolder to path to desktop folder
    end try
    tell application "Pages"
    activate
    set myDocument to make new document with properties {path:myFolder}
    end tell
    But this gets an error "Can't make [the selected folder] of application "Finder" into the expected type. (-1700).
    In automator, I've tried to do the following:
    1. Get Selected Finder Items (which will be the folder I want)
    2. (Create new variable "path" and drag onto 1., which creates "Get Value of variable)
    3. (ignoring input) Get Specified Finder Item (specifying a blank Pages document)
    4. (accepting input) Copy Finder Item to variable "path"
    The problem with this is that step 2 returns both the desired folder AND the desktop. The result of the entire process, moreover, is that the blank Pages file is created (or rather copied to) the desktop ONLY, and not to the desired folder.
    Anyway, I hope someone can help me with this. It would really speed up my organizing process.
    Wes

    Taking care of true window's properties is often useful
    on run
    try
    tell application "Finder" to set myFolder to (target of the front window) as alias
    on error -- no open folder windows
    set myFolder to path to desktop folder
    end try
    set myNewDoc to my makeNewIworkDoc("Pages", "myNewDocument" & my dateTimeStamp() & ".pages", myFolder as text)
    end run
    --=====
    Creates a new iWork document from Blank.template,
    saves it and returns its pathname.
    example:
    set myNewDoc to my makeNewIworkDoc(theApp, docName, folderPath)
    on makeNewIworkDoc(a, n, d)
    local t, c
    if a is "Pages" then
    set t to ((path to applications folder as text) & "iWork '09:Pages.app:Contents:Resources:Templates:Blank.template:") as alias
    else if a is "Numbers" then
    set t to ((path to applications folder as text) & "iWork '09:Numbers.app:Contents:Resources:Templates:Blank.nmbtemplate:") as alias
    else
    if my parleAnglais(theApp) then
    error "The application “" & a & "“ is not accepted !"
    else
    error "l’application « " & a & " » n’est pas gérée !"
    end if
    end if
    set f to d & n
    tell application a
    set c to count of documents
    open t
    repeat
    if (count of documents) > c then
    exit repeat
    else
    delay 0.1
    end if
    end repeat
    save document 1 in file f
    end tell -- theApp
    return f as alias
    end makeNewIworkDoc
    --=====
    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 dateTimeStamp()
    return (do shell script "date +P%Y%m%d-%H%M%S")
    end dateTimeStamp
    --=====
    Yvan KOENIG (VALLAURIS, France) vendredi 4 septembre 2009 20:51:02

  • Automator/applescript to forward junk mail as attachment...how?

    I finally came up with a real use for Automator and Applescript -- I was delighted.
    I want to modify my junk mail rule to run an Applescript that forwards a mail message as an attachment (not just a regular forward) to Spamcop.
    It has to be forwarded as an attachment. First shot, I simply went to modify my junk mail rule but, alas, found that "forward as attachment" is not an option for Mail's rules. Fortunately, there is a "run Applescript" option so...
    I fired up Automator, hoping to see how to tell Mail to forward a message as an attachment. Again, alas, no "as attachment" option there. So then I started exploring how to invoke the Mail menu item Message > Forward as Attachment but, haven't been able to figure it out.
    Any help would be appreciated. Especially since this will be the first time I've actually found a use for Automator, which is great... I just know it's not merely eye candy...

    Here is some starter code, to be saved into the current users' '~/Library/Scripts/Applications/Mail/' folder - as a script file ...
    using terms from application "Mail"
    on perform mail action with messages tMessages
    repeat with i in tMessages -- Cycle throught the list of incoming 'Rule' filtered e-Mail messages.
    -- File path file Name of temporary attachement file.
    set file_Name to (((path to home folder from user domain) as string) & (do shell script "date +%Y%m%d%H%M%StempFile.txt"))
    try -- Capture any unexpected AppleScript error.
    set FREF to open for access file file_Name with write permission -- Create temporary attachement file.
    write ((source of i) as string) to FREF starting at 0 -- Write to temporary attachement file.
    close access FREF -- Close temporary attachement file.
    -- Make new outgoing e-Mail message, and attach respective attachment file.
    set tMessage to make new outgoing message with properties {visible:true, subject:"My Subject", content:("My Body" & return & return)}
    tell content of tMessage
    make new attachment with properties {file name:(file_Name as alias)} at after last paragraph
    end tell
    end try
    try -- Capture any unexpected AppleScript error.
    tell application "Finder" to delete file file_Name -- Trash temporary attachement file.
    end try
    end repeat
    end perform mail action with messages
    try -- Capture any unexpected AppleScript error.
    tell application "Finder" to empty trash -- Delete all temporary attachement files (plus all other items) in the trash can.
    end try
    end using terms from

  • Automator/applescript help needed

    Basically I want to use automator and/or applescript to create a script that will add my current MAC address to a text file i specify (in the script) and then have a popup to enter a new one that also gets logged in the text file and then it changes to the new one. I need a way to paste the contents of the clipboard in to a terminal command. How can I do that?

    Note that Discussions has dedicated AppleScript & UNIX forums in Support > Discussions > Mac OS X Technologies & an Automator one in Support > Discussions > Mac OS X v10.5 Leopard. These would be better places to post if you are looking for detailed help with this.
    That said, take a peek at the man page for pbcopy, which provides Terminal access to the Mac clipboard. The "See Also" section has references to developer info for working with the clipboard.
    Message was edited by: R C-R

Maybe you are looking for