Applescript Advice ?

Does anyone know how to create a Folder that will only accept certain file types ??  IE: PDF, JPEG, TIFF.. but reject other file types IE: PSD, DOC etc.
Many thanks

property imageExtensions : {"tiff", "jpg", "gif", "png"}
on adding folder items to this_folder after receiving these_items
          repeat with this_item in these_items
                    tell application "System Events"
                              if name extension of this_item is in imageExtensions then
  -- right type, send to processing folder
                                        move this_item to folder "path:to:folder:where:filesAreProcessed"
                              else
  -- wrong type, move to trash folder
  delete this_item
                              end if
                    end tell
          end repeat
end adding folder items to
Save it as a normal script, and attach it to the drop folder as a folder action.

Similar Messages

  • AppleScript Advice - export all libraries in the aperture package?

    Not being an applescript expert - has anyone written a script to export all of the projects in a library (for instance on one's portable) so that they can be backed up to DVD and also imported into a central library (for instance on one's desktop)
    Any help would be very much appreciated
    TIA

    You don't need AppleScript for this - select the Library in the Finder, control-click and choose 'Show Package Contents', then copy each .approject file to the place you want them.
    Ian

  • Applescript help: Getting titles of certain windows

    I'm working on an AppleScript that will tell you the frontmost window and application that you're looking at, and I decided to add extra support for iTunes in to tell it what playlist you're looking at. Well, it's almost fully functional, except for the fact that the iPod Games pane and the iTunes store pane don't return a name or a special kind. I've tried everything I could, but there doesn't seem to be any way to tell them apart. Does anyone here know a way I can have the AppleScript determine this?
    Thanks!

    You may want to try posting this is the AppleScript forum, I think you're more likely to get expert AppleScript advice in a forum all about AppleScript B-)>

  • AppleScript - figured out a way to make it wait (sort of).. advice?

    i've been trying to write an applescript that acts sort of as a printing helper in sketchup (getting accurate prints from sketchup is way too confusing and actually impossible to really get it right)
    anyway, things were moving along nicely until i hit a brick wall as far as how i'd like the script to work..
    it came to a point where i needed the script to wait for the user to close a dialog in order to stop updating the variables is was getting..
    all my searches and everything i've read so far has said you can't do it in a single script but i might of figured out a way..
    here's the part i'm talking about: (the example uses textedit since i figure everyone has it and it uses the same print dialog as sketchup)
    tell application "TextEdit"
      activate
              tell application "System Events" to tell process "TextEdit"
      -- so i can get just the numbers from static text a little further down
                        set AppleScript's text item delimiters to {" "}
      -- probably a better way to talk to TextEdit than this?
      -- for sake of example, i'm doing it the same way as with sketchup
                        click menu item "Page Setup…" of menu 1 of menu bar item "File" of menu bar 1
      -- this is the part that will wait until the user clicks 'ok' in the
      -- 'page setup…' dialog.
      --the user can continue to change their paper size and the script will wait until they make a final selection.
      -- it's actually pulling the numbers from bit of text underneath the 'paper
      -- size' popup.. when the user changes the paper size, that bit of text updates
      -- and so do the script's variables..
                        repeat until focused of text area 1 of scroll area 1 of window 1 = true
                                  try
                                            set psz to value of static text 2 of sheet 1 of window 1
                                  end try
                        end repeat
      -- in my script, i also check for the paper orientation but it's not
      -- relevant for this thread..
                        set papw to first text item of psz
                        set paph to third text item of psz
      --not part of my script.. just an example of the numbers i want.
                        display dialog "width = " & papw & "
    height = " & paph
              end tell
    end tell
    i have had it fail a couple of times but in most cases, it makes it though.. i'll experiment a little more with it to try to stop those errors..
    i guess my question is -- why hasn't anyone done this before? (just kidding, they probably have but i couldn't find it online)
    or my actual question is -- is there anything inherantly wrong with this approach.. i mean, if i can get it to make it through consistently, is there a problem with it repeating / updating the variable so many times in a row? is it a drain on system resources or can it break anything etc.?
    thanks

    or my actual question is -- is there anything inherantly wrong with this approach.. i mean, if i can get it to make it through consistently, is there a problem with it repeating / updating the variable so many times in a row? is it a drain on system resources or can it break anything etc.?
    Although I'm far from being an expert in programming, I would answer NO. Imho, you've just got a brillant idea! (As for “repeating / updating the variable so many times in a row”… you could add a short delay (like “delay 1”) inside the repeat block, but I don't think it's a must.)

  • Total newbie to Automator and Applescripts needs advice.

    Hi All,
    I've read about all these great little apps that can do repetitive things for me. I can't wait to get started. I downloaded an applescript and, well, now what? What do I need to do to get it to run? It's an app that will quit all MS apps before backing up (that will prevent my MS database from getting corrupted, can't have that)--I want it to run on its own before my backup software kicks in.
    Thanks.

    May I suggest that you begin with the following links (in the specified order):
    1. [AppleScript: The Language of Automation|http://www.macosxautomation.com/applescript>
    2. [Beginner’s Tutorial: The First Step|http://www.macosxautomation.com/applescript/firsttutorial/index.html]
    3. [Essential Sub-routines: Overview|http://www.macosxautomation.com/applescript/sbrt/index.html]
    4. [AppleScript Language Guide|http://developer.apple.com/mac/library/documentation/AppleScript/Conceptu al/AppleScriptLangGuide/introduction/ASLRintro.html#//appleref/doc/uid/TP40000983-CH208-SW1]

  • Advice on creating video using AppleScript

    Hello all,
    I am developing a short film project that uses Morse Code. What I am trying to do is to input text into AppleScript and produce frames within Final Cut Pro.
    Has anyone had any experience with anything similar?
    Cheers,
    Nicholas

    Core Animation is a Leopard only feature, so it isn't available yet.
    I brought up Quartz, because I've done some Cocoa programming (in Objective-C) and know that it makes drawing bezier paths pretty easy. Then it would be a matter of just encoding it as a image file, and saving it out. Like I said, I'm not sure how (or if) you can use Applescript to do the same.
    If you don't have much programming experience, it could be a (very) overwhelming process. So if you're comfortable with Applescript, might want to stick with automating a drawing app.

  • Shellscript in Applescript

    I made a shell script that works until one point where the Escape key needs to be pressed. Does anybody know how to make applescript make a keystroke while inside of the shell script???

    theAnimator: I've followed you through several threads apparently trying to solve a simple problem, but it seems you are getting lots of partial answers and you are now trying to piece them together, but the real solution is much simpler. Instead of trying to turn that interactive process (where you need to type the escape character) into a non-interactive one, the interactive process that you're trying to adopt (perhaps with expect) was dubious advice. That problem could have been solved directly with a simpler non-interactive solution that doesn't rely on the keyboard.
    For example, if you can put the lines you want to insert into a file, "finsert", and you want to insert those lines between lines 12 and 13 of file fdata, the following Unix shell script would do that:
    # make backup
    cp fdata fdata.bak
    # copy first 12 lines
    head -n 12 fdata.bak > fdata
    # copy insert text
    cat finsert >> fdata
    # copy remainder
    tail -n +13 fdata.bak >> fdata
    Note the distinction between > and >> in the script.

  • Awkward shell script in Applescript

    Hi,
    I'm trying to get the following line of code to run in an Applescript:
    ifconfig | grep "inet " | grep 192.168 | cut -d\ -f2
    It works perfectly in terminal, but I can't for the life of me to work in an Applescript (I am aware of the double spacing requirements).
    Any advice would be most welcomed.

    Is this what you want?
    do shell script "ifconfig | awk '/inet/ { if (match($2, /192\.168\./)) print $2; }'"

  • AppleScript speed difference between 10.4 & 10.5

    This post is related to a question I posed in March 2009 (https://discussions.apple.com/message/9226100) regarding the speed difference between AppleScript text handling in OS X 10.5 compared with 10.4.11.
    I have recently written a script to search through a text file which is an xml file exported from WorkGroup Manager. The file, which is approximately 1.8 MB, contains all the user names on the school server (just over 1720 of them), their settings and any other information we have added. After adapting some script ideas (using text delimiters and offsets) which I found on the internet to assist with counting the number of users and searching through the information of each one, one at a time, I have a script which works far in excess of my expectations in terms of speed when run under OS X 10.4, but runs slower than molasses in winter under 10.5.
    The script counts the number of accounts, extracts each user's log-in name and also their actual name (which we have entered under a 'general info' or 'comments' field - I can't remember exactly where, but it is stored in the file), makes up a complete list of all account names (with the actual name, if present) and also makes up a subset of this information into a separate list which contains only the log-in names of those whose actual name has not yet been recorded on the server, then saves both lists to separate text files.
    My original attempts, using some rather clumsy text searching and comparison techniques, took about 1-2 minutes to go through the whole procedure. After some internet searching, head-scratching and a bit more more work, the finished script, when run on my G5 under OS X 10.4.11, takes less than 3 seconds to do all I have described above, including the writing to text files. To say I was pleased would be an understatement!
    Because the school/work environment, where the script would be run, is all OS X 10.5 or higher, I thought I should test it out under at least OS X 10.5. The script was developed on my DP 2.5GHz G5 with 8GB RAM running OS X 10.4.11. Using a fresh, clean installation of 10.5 I ran the script and was extremely disappointed. After letting it run for more than 20 minutes and still not finishing, I force quit AppleScript and reduced the number of accounts in the file. 40 accounts took 3 seconds, 60 accounts took 6 seconds, 80 took 11 seconds, 100 took 19 seconds and 120 took 27 seconds. I eventually let the script run right through - total time taken to process 1720 users was 65 minutes, compared to 3 seconds under 10.4.11!
    Given that it was tested on the same Mac, with the same amount of RAM, using the same script and the same original text file, the only variable left (that I can think of) is the change of OS version - 10.4.11 vs 10.5.
    As was pointed out to me in my previous post, AppleScript in OS X 10.5 handles all text as Unicode and has a greater overhead in processing time as a result. I have implemented the various bits of advice offered by respondents to my original post and changed the way I handled lists, etc. Obviously, if the script works so speedily under 10.4.11, I must have done something right in terms of code optimization/efficiency. It's when that exact same script is run under OS X 10.5 that it slows down incredibly. I even tried it on a 2.66GHz Intel Core 2 Duo iMac running 10.5.8 - it still took 40 minutes and Activity Monitor showed CPU usage by Script Editor constantly above 80% (often well above 90%). Saving the script as an application made no difference in the time taken.
    Does anybody have any knowledge about what makes AppleScript Unicode-only text handling so slow? In this case, it is 1300 times slower! Is there any way of coercing/restricting the text handling/parsing to ASCII? If I really have to, I will set up a humble eMac at school with 10.4 on it just to handle large text files quickly with AppleScript, but I would prefer to be able to do it on the normal work Macs which have 10.5 or later on them. As mentioned, under 10.4.11 the script processes the 1.8MB text file with 1720 users and writes results to two files - all within 3 seconds, so I'm not really looking for coding suggestions unless they are directly related to what has changed in AppleScript under OS X 10.5. Without sounding too smug, the script works properly and speedily (at least in 10.4). I really would like to learn about the changes in AppleScript in OS X 10.5 and how to cope with or work around those changes.

    Hi,
    text 3 thru 14 in largeText
    character 3 thru 14 in largeText
    text 3  in largeText
    character 3  in largeText
    These lines will be slow on Leopard
    Getting some text in a variable that contains more than 60000 characters will be slower on Leopard,
    but I don't know why it's slower
    Here a test script.
    script o
        property t_text : ""
    end script
    set a to "abcdefghij"
    set tResult to ""
    repeat with i from 1 to 3
        set o's t_text to a
        repeat (item i of {17, 15, 14}) times
            set o's t_text to o's t_text & o's t_text -- add  characters in the variable
        end repeat
        set StartTime to current date
        -- test
        repeat 20 times
            set b to text 3 thru 14 in o's t_text -- get a text in the variable
        end repeat
        -- end test
        set EndTime to current date
        set TimeTaken to EndTime - StartTime
        set tResult to tResult & " Getting text in the variable which contains " & length of o's t_text & ", (20 times) = " & TimeTaken & " seconds." & return
    end repeat
    tResult
    Here the result on my old G5, 2 x 1.8 GHZ
    Getting text in the variable which contains 1310720 characters, (20 times)  = 50 seconds.
    Getting text in the variable which contains   327680 characters, (20 times)  = 12 seconds.
    Getting text in the variable which contains   163840 characters, (20 times)  =   6 seconds.
    The result on the same machine on Tiger is always less of one second.
    Also, I try with 20 millions characters on Tiger, the result : getting text in the variable which contains 20971520 characters, (20 times)  = 0 seconds.
    The solution ( text item in a list)
    Here the script
    script o
        property my_List : {}
    end script
    set OldDelims to text item delimiters
    set RecordDelimiter to "::::::::::::::"
    set LengthOfRecordDelimiter to length of RecordDelimiter
    set o's my_List to findAll(read (choose file), RecordDelimiter)
    on findAll(str, findString)
        set Oldtid to text item delimiters
        try
            set text item delimiters to findString
            if str does not contain findString then return {"Nothing found"}
            set t to str's text items
            set text item delimiters to Oldtid
            return t
        on error eMsg number eNum
            set text item delimiters to Oldtid
            error "Can't findAll: " & eMsg number eNum
        end try
    end findAll
    set NumberOfrecords to (count o's my_List)
    display dialog "There are " & NumberOfrecords & " accounts."
    set StartTime to current date
    set text item delimiters to ":"
    set FullUserList to {}
    set ListOfUnnamedUsers to {}
    -- first user needs to be done separately as it is not preceded by RecordDelimiter
    set EndOfHeader to "Standard:URL"
    set LengthOfEndOfHeader to length of EndOfHeader
    set EndOfHeaderOffset to the offset of EndOfHeader in (item 1 of o's my_List)
    set OffsetToApply to EndOfHeaderOffset
    set TextBeingChecked to text (OffsetToApply + LengthOfEndOfHeader + 1) thru -1 of (item 1 of o's my_List)
    tell TextBeingChecked to set {UserName, NameForInfo} to {text item 1, text item 7}
    if NameForInfo = "" then set end of ListOfUnnamedUsers to UserName & return
    set end of FullUserList to (UserName & tab & NameForInfo & return)
    -- now do all the others
    repeat with CounterG from 2 to (NumberOfrecords - 1)
        set TextBeingChecked to item CounterG of o's my_List
        tell TextBeingChecked to set {UserName, NameForInfo} to {text item 1, text item 7}
        if NameForInfo = "" then set end of ListOfUnnamedUsers to UserName & return
        set end of FullUserList to (UserName & tab & NameForInfo & return)
    end repeat
    set o's my_List to {}
    set text item delimiters to OldDelims
    -- write results to file
    -- 1). full user list
    set TargetFile1 to (path to desktop folder as string) & "FullUserList1.txt"
    try
        open for access file TargetFile1 with write permission
    on error
        close access file TargetFile1
        open for access file TargetFile1 with write permission
    end try
    set EndTime to current date
    beep
    set InfoToBeWrittenToFile to FullUserList as text
    write InfoToBeWrittenToFile to file TargetFile1
    close access file TargetFile1
    -- 2). list of users without NameForInfo
    set TargetFile2 to (path to desktop folder as string) & "UnnamedUsersList1.txt"
    try
        open for access file TargetFile2 with write permission
    on error
        close access file TargetFile2
        open for access file TargetFile2 with write permission
    end try
    set InfoToBeWrittenToFile to ListOfUnnamedUsers as text
    write InfoToBeWrittenToFile to file TargetFile2
    close access file TargetFile2
    beep 3
    set TimeTaken to EndTime - StartTime
    set TimePerAccount to TimeTaken / NumberOfrecords
    display dialog (NumberOfrecords & " accounts took " & TimeTaken & " seconds." & return & return & "That equals " & TimePerAccount & " seconds per account.") as string

  • Applescript works in Automator, but not when app is opened - running all if statements at once?

    Good evening,
    I am new to applescript and have a newbie question regarding the following code. I am making a simple automator program to pull songs from iTunes to practice dancing to. I've started the program with a script that lets the user choose which dances (s)he wants to be played. Then I use applescript to run if statements for each dance, checking whether the dance was selected (and is therefore in "danceList"). If so, I call a separate app to handle finding and playing that dance. The whole thing runs perfectly once opened in automator.
    The problem is when I try to open the app for the first time, whether in finder or in automator -- it calls every single one of the if-statement applications, all at once, before anything else has happened, and thus crashes itself. I have no idea why. I have searched various help sites, tried multiple variations of the if statement code (waltz is an example, below) and making the sub-applications into workflows, but that didn't help.
    Any advice or pointers in the right direction/to appropriate resources would be greatly appreciated.
    Here is a snippet from the relevant code: (didn't include it all, it's the same thing with more if statements)
    on run {danceList}
              if danceList is not null then
                        if danceList contains "Waltz" then
                                       tell application "waltz"
                                                      run
                                       end tell
                                       delay 110
                        else
                                       tell application "waltz"
                                                      quit
                                       end tell
                        end if
                        if danceList contains "Tango" then
                                       tell application "tango"
                                                      run
                                       end tell
                                       delay 110
                        end if
                        if danceList contains "Viennese Waltz" then
                                       tell application "viennese"
                                                      run
                                       end tell
                                       delay 110
                        end if
    ... and so forth ...
        end if
        return danceList
    end run

    Ok, let me try to do a better job explaining.
    I am making this app to simulate the rounds used in competitive ballroom dancing. It lets the user select the dances they will participate in, and then, for each dance, the program reads out the dance title, chooses all songs in iTunes with that genre, selects one at random, starts playing it, waits ninety seconds, and then stops the music. Then a twenty second pause before the next dance. I have made eleven apps for this; one is the main app that calls the others; the others are identical and handle the individual dances.
    Here is all the code I have:
    1. Ask for confirmation - dialogue box explaining app
    2. Get specified text - list of all dances, passed to first section of applescript
    3. First section of script - found on internet, altered for multiple selection; lets user choose multiple dances from a list (code is below pic)
    on run {input, parameters}
    choose item(s) from text
    input: text - items are delimited by paragraphs (returns/newlines)
    output: a list of paragraphs selected
              set output to {}
              set NameList to {}
              set NameList to paragraphs of (input as text)
      activate me
              set TheChoice to (choose from list NameList with title "Choose Dances" with empty selection allowed and multiple selections allowed)
              if TheChoice is false then
                        error number -128 -- cancel
              else
                        set output to TheChoice
              end if
              return the output -- pass the result to the next action
    end run
    4. Store value of variable as "danceList" - probably unnecessary but gave it a name
    5. Second section of applescript - what's been discussed previously, here's the full code:
    on run {danceList}
              if danceList is not "" then
                        if danceList contains "Waltz" then
                                  tell application "waltz"
                                            run
                                  end tell
                                  delay 110
                        end if
                        if danceList contains "Tango" then
                                  tell application "tango"
                                            run
                                  end tell
                                  delay 110
                        end if
                        if danceList contains "Viennese Waltz" then
                                  tell application "viennese"
                                            run
                                  end tell
                                  delay 110
                        end if
                        if danceList contains "Foxtrot" then
                                  tell application "foxtrot"
                                            run
                                  end tell
                                  delay 110
                        end if
                        if danceList contains "Quickstep" then
                                  tell application "quickstep"
                                            run
                                  end tell
                                  delay 110
                        end if
                        if danceList contains "Samba" then
                                  tell application "samba"
                                            run
                                  end tell
                                  delay 110
                        end if
                        if danceList contains "Cha cha" then
                                  tell application "chacha"
                                            run
                                  end tell
                                  delay 110
                        end if
                        if danceList contains "Rumba" then
                                  tell application "rumba"
                                            run
                                  end tell
                                  delay 110
                        end if
                        if danceList contains "Paso Doble" then
                                  tell application "paso"
                                            run
                                  end tell
                                  delay 110
                        end if
                        if danceList contains "Jive" then
                                  tell application "jive"
                                            run
                                  end tell
                                  delay 110
                        end if
              end if
              return danceList
    end run
    Here is the code for the waltz app. All the other dance apps are identical; they just search for different terms and have a different introduction spoken.
    1. Get specified text - "Next Round is the Waltz, etc."
    2. Speak text - reads text out loud so people know what's next
    3. Find iTunes tracks where genre is "Waltz" or "waltz"
    4. select these tracks
    5. store all these in variable "tracks"
    6. applescript to pick a random track from "tracks":
    on run {tracks}
              set maxNumber to count of tracks
              set randy to random number from 1 to maxNumber
              set chosenTrack to item randy of tracks
              return chosenTrack
    end run
    7. 3 second pause between speech and music
    8. Start playing the chosen track
    9. 90 second wait while track plays
    10. pause itunes (stop music)
    11. end app
    Again, my concern here is why the program runs fine once it has already been opened in automator (say second or third time running it there) but when run from finder, or first opened in automator, it calls all the dance apps at once. Then they give error messages because the speech section is first, and this can't be done simultaneously:
    Also, not sure if this is relevant, but I have a spinning gear in the corner of my mac that I believe is automator launcher, and it's showing all the apps as running even after I've ok'd their error messages and they have disappeared from the dock. I can exit waltz and danceApp, which are the two actually running, but the others won't stop until I've ended automator launcher in activity monitor.
    Hopefully this is more helpful. Thanks again.

  • How to send a mail as an attachment in a mail with AppleScript?

    Hi,
    I want to manage my spam using the advices found in support.apple website :
    OS X Mail
    Open the message and choose “Forward as Attachment” from the Message menu.
    Forward the message to iCloud [email protected].
    Forward the message again to abuse@domain, replacing domain with the part of the sender's email address after the @ symbol. For example, if the sender's email address is [email protected], forward the message to [email protected].
    I don't know how to make a message as an attachment...
    set theAttachment to theMessage
    make new attachment with properties {file name:theAttachment} at after last paragraph
    Here is my whole script, if it runs, it could be useful :
    tell application "Mail"
      -- envoi les messages sélectionnés en PJ à [email protected]
              set theMessages to the selection
              repeat with theMessage in theMessages
                        set theAttachment to theMessage
                        set newMessage to make new outgoing message at end of outgoing messages
                        tell newMessage
                                  set subject to "Fwd: " & theMessage's subject
      make new to recipient with properties {address:"[email protected]"}
                                  tell content of theMessage
      make new attachment with properties {file name:theAttachment} at after last paragraph
                                  end tell
                        end tell
      send newMessage
              end repeat
      -- envoi les messages sélectionnés en PJ à abuse@<domaine du spammeur>
              set theMessages to the selection
              repeat with theMessage in theMessages
                        set theAttachment to theMessage
                        set newMessage to make new outgoing message at end of outgoing messages
                        tell newMessage
                                  set subject to "Fwd: " & theMessage's subject
                                  set theSpamAddress to theMessage's sender
                                  set AppleScript's text item delimiters to {"@"}
                                  set spamerDomainName to text item 2 of theSpamAddress
                                  set theNewSpamAddress to "abuse@" & spamerDomainName
      make new to recipient with properties {address:theNewSpamAddress}
                                  tell content of theMessage
      make new attachment with properties {file name:theAttachment} at after last paragraph
                                  end tell
                        end tell
      send newMessage
              end repeat
    end tell
    Thank you!

    Perfect!
    You clearly give me the way. Actually I have used the AppleScript Language Guide from https://developer.apple.com to finalize my AppleScript.
    You just need to select the spam message(s) in "Mail" application, then run the script.
    As I mentionned previously, it just do this automatically :
    OS X Mail
    Open the message and choose “Forward as Attachment” from the Message menu.
    Forward the message to iCloud [email protected].
    Forward the message again to abuse@domain, replacing domain with the part of the sender's email address after the @ symbol. For example, if the sender's email address is [email protected], forward the message to [email protected].
    Here is the entire working script :
    -- Ce script permet de lutter contre le spam.
    -- Je me suis appuyé sur les conseils sur http://support.apple.com/kb/TS4019?viewlocale=fr_FR
    tell application "Mail"
              set theMessages to the selection
              repeat with theMessage in theMessages
      -- enregistre le message dans un fichier pour le mettre en PJ ensuite
                        set msgContent to source of theMessage
                        set tmpFile to ((path to desktop) as rich text) & "ForwardedMessage"
                        set referenceNumber to open for access tmpFile with write permission
      write msgContent to referenceNumber
      close access referenceNumber
      -- envoi le message sélectionné en PJ à [email protected]
                        set newMessage to make new outgoing message at end of outgoing messages
                        tell newMessage
                                  set subject to "Fwd: " & theMessage's subject
      make new to recipient with properties {address:"[email protected]"}
                                  tell content of newMessage
      make new attachment with properties {file name:tmpFile} at after last paragraph
                                  end tell
                        end tell
      send newMessage
      -- envoi le message sélectionné en PJ à abuse@<domaine du spammeur>
                        set newMessage to make new outgoing message at end of outgoing messages
                        tell newMessage
                                  set subject to "Fwd: " & theMessage's subject
                                  set theSpamAddress to theMessage's sender
                                  set AppleScript's text item delimiters to {"@"}
                                  set theSpamAddress to text item 2 of theSpamAddress
                                  set AppleScript's text item delimiters to {">"}
                                  set spamerDomainName to text item 1 of theSpamAddress
                                  set theNewSpamAddress to "abuse@" & spamerDomainName
      make new to recipient with properties {address:theNewSpamAddress}
                                  tell content of newMessage
      make new attachment with properties {file name:tmpFile} at after last paragraph
                                  end tell
                        end tell
      send newMessage
              end repeat
    end tell

  • AppleScript: Waiting for a user to enter user name and password

    I'm currently working on an AppleScript designed to automate binding a computer to Active Directory and another script to install a login certificate. While you can create a UNIX shell script for the Active Directory binding, I found that you have to have your user name and password in the script itself and this system will be deployed by multiple people.
    So instead I'm doing an GUI Automation AppleScript of Directory Utility. What I'd like to do is have the script to wait for the admin user (who will be remoting in by ARD) to enter their Network user and password, click okay and then continue the script to quit the program and then run a self-destruct (which I'd also appreciate any advice about doing in AppleScript)
    Here's the script so far, which I've set up successfully:
    activate application "Directory Utility"
    tell application "System Events"
      click text field 1 of row 1 of table 1 of scroll area 1 of group 1 of group 1 of window "Directory Utility" of application process "Directory Utility"
      click button 1 of group 1 of group 1 of window "Directory Utility" of application process "Directory Utility"
      click text field 2 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      keystroke "EXAMPLE.COMPANY.com"
      click UI element 3 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      click radio button "Administrative" of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      click checkbox "Allow administration by:" of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      click button 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      click row 1 of table 1 of scroll area 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      keystroke "GroupExamplePS NA"
      click button 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      click row 2 of table 1 of scroll area 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      keystroke "GroupExampleNA"
      click button 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      click row 3 of table 1 of scroll area 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      keystroke "GroupExampleNATemps"
      click button 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      click row 4 of table 1 of scroll area 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      keystroke "GroupExampleTeam 1"
      click button 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      click row 5 of table 1 of scroll area 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      keystroke "GroupExampleTeam 2"
      click button 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      click row 6 of table 1 of scroll area 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      keystroke "GroupExampleTeam 3"
      click button 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      click row 7 of table 1 of scroll area 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      keystroke "GroupExampleDesktop Admins"
      click button 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      click row 8 of table 1 of scroll area 1 of tab group 1 of sheet 1 of window "Directory Utility" of application process "Directory Utility"
      keystroke "GroupExampleDomain Admins"
      click button "Bind…" of sheet 1 of window "Directory Utility" of application process "Directory Utility
    <<WAIT LINE HERE FOR NETWORK ADMIN AND AND PASS, THEN USER WILL CLICK OKAY, THEN CONTINUE SCRIPT>>
    <<QUIT ACTIVE DIRECTORY>>
    <<SELF-DESTRUCT>>
    end tell
    It isn't a real command prompt like if you're changing System Preferences or something. It's a specialized prompt specifically for Directory Utility. However, I do need to know how to make AppleScript wait for a password for a standard Password Prompt for adding a certificate to the login keychain through Keychain Access. I've also done pretty much the same thing as above for that script.
    Any tips would be GREATLY appreciated.

    Yeah, I know GUI Scripting is not the best way, but I couldn't find a successful variable system for the following script. The other issue is that I'd prefer to send this by ARD and have ARD ask for a User Name and Password, but I've found there's no way to do that. Then again, I can't send the AppleScript purely remotely either.
    What I mean by self-destruct is simply I only want the Active Directory binding script to run once upon login to the primary admin user and then delete itself so it doesn't get run again. The login certificate script I want to run once on each new user who logs in (so I'll likely be putting it in the "User Template") and then delete itself so it doesn't run the next time they log in. I can't figure out any way to hit those buttons through a shell script.
    Here's the original UNIX shell script: (This is what I'm using temporarily until I figure out a solution that doesn't require my user name and password to be embedded)
    #! /bin/bash
    MACNAME=$(scutil --get ComputerName)
    dsconfigad -add "CORP.DOMAIN.NET" \
    -username USER \
    -password PASS \
    -computer $MACNAME \
    -mobile disable \
    -mobileconfirm disable \
    -localhome enable \
    -useuncpath enable \
    -shell /bin/bash \
    -ou OU=Macs,CN=Computers,DC=corp,DC=DOMAIN,DC=net \
    -force \
    -localpassword "PASSWORD" \
    -groups "GROUPS"
    And here is the Certificate Installation AppleScript
    activate application "Keychain Access"
    tell application "Finder" to open POSIX file "/FolderName/Certificate.crt"
    delay (3)
    tell application "System Events" to tell process "Keychain Access"
      click button "Add" of window "Add Certificates"
      click button "Always Trust" of group 3 of sheet 1 of window "Keychain Access"
    end tell
    Thanks for the help. I really appreciate it. This is a rather new field for me and most of my knowledge comes from Google Searches and about a billion tabs trying to find answers.

  • Unable to print with AppleScript

    Hi all,
    I would like to print a PDF document via AppleScript. I tried to use a the following AppleScript code
    set my_pdf to "/Users/fabrice/tmp/a.pdf"
    tell application "Adobe Reader"
    activate
    open (my_pdf)
    print
    end tell
    end run
    After script execution, the document is correctly in opened in Adobe Reader, but there is a dialog box with the following message: "AppleScript Error: Error in Abode Reader : unable to continue with print".
    It seems that the "print" command is not recognized as an Adobe events.
    For information, i'm never be able to successfully execute the "PrintPage.applescript" found in the "Acrobat 9 SDK". It doesn't compile.
    Any advices ? Thanks for your help ?

    Printing is a Function, of the system Your going to figure out how to open the PDF then have system call the printer. Note while Printing is a Function of the System it is called from with the application. If this will help the Command key  + the P Key opens the Print Window. I am not a person that uses Applescript so I can not tell you how to make the script.

  • AppleScript (or Automator?): How to search through online сhеss games?

    Hello.
    I would like to search for specific online сhеss games. Each game has a single adress. We are talking about millions of games. Obviously, it's far too long to index all the games. So I will set a limit and use the script at night. Conditions should be something like this:
    For adress example.com/game=NumberA to example.com/game=NumberB
    Search every web page containing SpecificWord
    Store wanted web adresses somewhere (so I could see the games by myself during the day)
    As you can see, I know nothing about Applescript and I don't know how to start, nor how the script can pick up adresses. I think it's possible and not difficult to code, just time consuming for the program to search through thousands of games.
    Should I use AppleScript or Automator? Should the script open Safari (or Firefox if possible) or can it search without any browser? Is it possible to simultaneously search through multiple pages/adresses? Maybe I could write several scripts for different ranges of games? If so, how many pages can I open at once? For instance I could disable images in Firefox to load quicker. How much time does it need to search for one game? 1, 2, 3, 4, 5 seconds?
    Any easy tutorials, examples of similar codes, advices, hints or tips are appreciated.

    Thanks for answering. Sorry that I was so unclear. My main problem was how to get urls and games id as variables. But then I thought there already should be programs doing web crawling. I have found Scrapy which use Python language.
    (Maybe I should edit my question, add Scrapy and Python as tags instead of applescript and automator. Is it possible?)
    I have Mac OS 10.6.8, Python 2.6.1. Scrapy needs at least Python 2.7 so I have downloaded the last version of Python (3.3).  I think I can handle the programming in Scrapy thanks to their tutorial. The most difficult part should be... how to install Scrapy. Don't laugh at me.
    I have entered "sudo easy_install Scrapy" in the terminal. But the terminal still uses Python 2.6.1. Python 3.3 is installed but I don't know how to clean update Python. If anyone knows, feel free...
    When I write scrapy in the terminal, here is what I get:
    Traceback (most recent call last):
      File "/usr/local/bin/scrapy", line 4, in <module>
        import pkg_resources
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg _resources.py", line 2556, in <module>
        working_set.require(__requires__)
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg _resources.py", line 620, in require
        needed = self.resolve(parse_requirements(requirements))
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg _resources.py", line 518, in resolve
        raise DistributionNotFound(req)  # XXX put more info here
    pkg_resources.DistributionNotFound: lxml
    It seems Scrapy also needs something called lxml. Right now I am trying to make Python 3.3 the default python version. Is there a web crawler GUI which already includes Python, Scrapy, lxml?
    By default I also have Python 2.4 and 2.5. Does the system need them? I prefer not to delete system files but together all Python versions weigh 500 MB.
    In regard to the real example URL: let's say instantchess.com. Here's a game URL: http://www.instantchess.com/?EXP=1&GPI=84094532
    84094532 is the game id. Let's say I want to search every Reti openings (thus the page must contain the word "Reti") from id 84000000 to 85000000 and store games id in my computer. If I have understood correctly, I need to search through the source code of the pages.
    Feel free to add any remarks, suggestions, ideas.

  • How can I add javascript text fields to Acrobat pages from Applescript please?

    I have a real need to add text fields to Acrobat document pages from Applescript. I can't access the Headers and Footers from Applescript in Acrobat XI. I can set watermarks using the following script, but cannot for the life of me work out how to add text fields. Any advice please?
    Regards
    set TempAttachmentName to "(20140717121212Z)"
    set PreserveFileName to "This is a test"
    set bypass to false
    tell application "Adobe Acrobat Pro"
      activate
      set CountOfPages to count of pages
      repeat with PageCounter from 1 to CountOfPages
      tell application "System Events" to tell process "AdobeAcrobat"
      try
      click menu item "Page..." of menu 1 of menu item "Go To" of menu 1 of menu bar item "View" of menu bar 1
      tell current application to delay 0.1
      keystroke PageCounter as text
      tell current application to delay 0.1
      keystroke return
      if not bypass then
      my ADDHeaderFooter(TempAttachmentName, PreserveFileName & " " & CountOfPages, PageCounter)
      end if
      end try
      end tell
      end repeat
    end tell
    on ADDHeaderFooter(The_String1, The_String2, currentPage)
      tell application "Adobe Acrobat Pro"
      activate
      set myDocument to document 1
      tell myDocument
      tell page currentPage
      set cbox to crop box
      set item 2 of cbox to (item 2 of cbox) + 44
      set item 4 of cbox to (item 4 of cbox) - 44
      set media box to cbox
      set crop box to cbox
      set theResult1 to my Add_WaterMarkText(The_String1, "IDAutomationHC39M", 12, 1, 1, 1, 0, 3, 10, 3, 0)
      do script theResult1
      set theResult2 to my Add_WaterMarkText(The_String2, "Times", 16, 1, 1, 1, 0, 4, 10, -6, 0)
      do script theResult2
      end tell
      end tell
      end tell
    end ADDHeaderFooter
    on Add_WaterMarkText(cText, cFont, nFontSize, nS, nE, nTA, nHA, nVA, nHV, nVV, nR)
      set Params to "cText: '" & cText & "'," & return
      set Params to Params & "cFont: '" & cFont & "'," & return
      set Params to Params & "nFontSize: '" & nFontSize & "'," & return
      if class of nS is integer then set Params to Params & "nStart: " & (nS - 1) & "," & return
      if class of nE is integer then set Params to Params & "nEnd: " & (nE - 1) & "," & return
      -- 0 = left, 1 = centre, 2 = right
      if class of nHA is integer then set Params to Params & "nHorizAlign: " & nHA & "," & return
      -- 3 = top, 4 = bottom
      if class of nVA is integer then set Params to Params & "nVertAlign: " & nVA & "," & return
      -- offset in points
      if class of nHV is integer then set Params to Params & "nHorizValue: " & nHV & "," & return
      -- offset in points
      if class of nVV is integer then set Params to Params & "nVertValue: " & nVV & "," & return
      if class of nR is integer then set Params to Params & "nRotation: " & nR & "," & return
      set javascript to "this.addWatermarkFromText({" & Params & "});"
      return javascript
    end Add_WaterMarkText

    G'day
    Unfortunately I don't have the API. My Adobe Reader installation updating to version XI failed, and subsequent attempts to fall back on the X version are blocked by the partial install of XI. Damn Adobe stuff.
    Could someone please post the relevant part of the API to give me some pointers, please.
    I ha mucked about with some information I found on the Web, and come up with the following, which fails because I can't work out how to address the current document with the variable myDoc.
    Regards, Brian
    set Params to Params & "var myDoc = this;" & return
    set TempAttachmentName to "(20140717121212Z)"
    set PreserveFileName to "This is a test"
    set bypass to false
    tell application "Adobe Acrobat Pro"
      activate
      set CountOfPages to count of pages
      repeat with PageCounter from 1 to 1 # CountOfPages
      tell application "System Events" to tell process "AdobeAcrobat"
      try
      click menu item "Page..." of menu 1 of menu item "Go To" of menu 1 of menu bar item "View" of menu bar 1
      tell current application to delay 0.1
      keystroke PageCounter as text
      tell current application to delay 0.1
      keystroke return
      if not bypass then
      my ADDHeaderFooter(TempAttachmentName, PreserveFileName & " " & CountOfPages, PageCounter)
      end if
      end try
      end tell
      end repeat
    end tell
    on ADDHeaderFooter(The_String1, The_String2, currentPage)
      tell application "Adobe Acrobat Pro"
      activate
      set myDoc to document 1
      tell myDoc
      tell page currentPage
      set cbox to crop box
      set item 2 of cbox to (item 2 of cbox) + 44
      set item 4 of cbox to (item 4 of cbox) - 44
      set media box to cbox
      set crop box to cbox
      set theResult1 to my Add_WaterMarkText(The_String1, "IDAutomationHC39M", 12, 1, 1, 1, 0, 3, 10, 3, 0, myDoc)
      do script theResult1
      set theResult2 to my Add_WaterMarkText(The_String2, "Times", 16, 1, 1, 1, 0, 4, 10, -6, 0, myDoc)
      do script theResult2
      end tell
      end tell
      end tell
    end ADDHeaderFooter
    on Add_WaterMarkText(cText, cFont, nFontSize, nS, nE, nTA, nHA, nVA, nHV, nVV, nR, myDoc2)
      #set Params to "var myDoc = app.newDoc();" & return
      set Params to ""
      set Params to Params & "var myDoc = this;" & return
      set Params to Params & "var inch = 72;" & return
      set Params to Params & "var Bbox = this.getPageBox(" & "\"Crop\"" & ");" & return
      set Params to Params & "var f = myDoc.addField(" & "\"Text1\"" & ", " & "\"" & cText & "\"" & ", 0, [72, Bbox[1]-inch, Bbox[2]-2*inch, Bbox[1]-2*inch ] );" & return
      set Params to Params & "f.strokecolor = color.black;" & return
      set Params to Params & "f.richText = true;" & return
      set javascript to Params
      return javascript
    end Add_WaterMarkText

Maybe you are looking for