AppleScript: System Events - delete

I've been trying to get System Events delete command to accept multiple files and no matter how I try to preset the files to the delete command I get an error.
According to the dictionary entry for System Events - delete it would appear it should take multiple files:
delete v : Delete disk item(s).
delete disk item : The disk item(s) to be deleted.
This is what I have
tell application "System Events"
          set ss to every disk item in desktop folder whose name contains "Screen Shot" and name extension is "png"
  delete ss
end tell
And this is the log window
tell application "System Events"
  get every disk item of desktop folder whose name contains "Screen Shot" and name extension = "png"
  --> {file "Mac OS Lion:Users:frank:Desktop:Screen Shot 2013-03-22 at 14.31.02 .png", file "Mac OS Lion:Users:frank:Desktop:Screen Shot 2013-03-22 at 14.31.17 .png"}
  delete {file "Mac OS Lion:Users:frank:Desktop:Screen Shot 2013-03-22 at 14.31.02 .png", file "Mac OS Lion:Users:frank:Desktop:Screen Shot 2013-03-22 at 14.31.17 .png"}
  --> error number -1700 from {file "Mac OS Lion:Users:frank:Desktop:Screen Shot 2013-03-22 at 14.31.02 .png", file "Mac OS Lion:Users:frank:Desktop:Screen Shot 2013-03-22 at 14.31.17 .png"} to reference
Result:
error "System Events got an error: Can’t make {file \"Mac OS Lion:Users:frank:Desktop:Screen Shot 2013-03-22 at 14.31.02 .png\", file \"Mac OS Lion:Users:frank:Desktop:Screen Shot 2013-03-22 at 14.31.17 .png\"} into type reference." number -1700 from {file "Mac OS Lion:Users:frank:Desktop:Screen Shot 2013-03-22 at 14.31.02 .png", file "Mac OS Lion:Users:frank:Desktop:Screen Shot 2013-03-22 at 14.31.17 .png"} to reference
Now if I do
delete item 1 of ss
the file is deleted. Also if I do a repeat through the list I can delete each file.
I've tried every which way I can thing of to play with the list to get multiple files to delete with no success. But I have to admit that file references still send me to the book to get it right.
So what basic bit of AppleScript vodoo am I missing or is this one of those cases where the dictionary does not match the code?
thanks

The only way I've ever been able to get that to work is to do the delete immediately:
tell application "System Events"
          delete (disk items of desktop folder whose name contains "Screen Shot" and name extension = "png")
end tell
it seems that when you store it into a variable, system events no longer accepts it.  The only reason I can think for this is that the scripting dictionary asks for a disk item rather than a list of disk items.  It's possible that editing the scriptSuite files to tell it to accept a list would solve the issue, but I've never experimented.

Similar Messages

  • AppleScript System Events Choose File Name Statement Broken?

    Re: OS X 10.9.2, AppleScript Editor 2.6.1:
    Why does the following AppleScript statement hang the Script Editor?
    tell application "System Events" to ¬
      choose file name with prompt "Output File" default name "Output File" default location (path to desktop)

    see Applescript Release Notes, Scripting Addition Security.
    Applescript, unlike other scripting languages, relies heavily on functionality being provided by client applications. This makes it much harder to keep consistent behavior across different contexts, because it's up to individual providers to implement applescript commands. A fact of Applescript life.
    However, it seems your real problem is not with System Events, but with the fact that your dialog is getting lost off-screen. This works:
    tell application "System Events"
      activate
      choose file name
    end tell

  • Applescript: system events keystroke to background?

    Is there a way to make system events send a keystroke to an application that is in the background (already running no need for activation) without bringing it to the foreground?
    i've looked in several places and can't find a way to do this.

    Sending keystrokes is just imitating what a user can do/does on the keyboard. You can no more send a keystroke to an app via System Events that isn't the front and active application than you can type text into a window that is in the background.
    The only way to deal with apps that aren't active is to script them directly. If they're not applescript-able, consider whether you can do it with a bash or python script instead.

  • AppleScript 10.9.0 System Events -10006  Update property list file item

    Have AppleScript that runs without error on Mountain Lion 10.8.5, but errors out on Mavericks  10.9.0.
    At end of script, property list items need to be updated and this is when error occurs.
    Put together a subset of the script, see below) that get the error
    Statement reads "set value of property list item "ArrayList001" to ArrayList001"
    Text of error:
         error "System Events got an error: 'xxx.plist' is not a property list file."
         number -10006 from contents of property list file "xxx05.plist"
    =============================================================================
    property myPListFile : "cbmck05.plist"
    property myPListFilePath : ""
    property constPreviousRunDay : "PreviousRunDay"
    on run
       set today to "Date01" as string
              set List001 to {}
              set List002 to {}
              set myPListFilePath to ""
              repeat with i from 1 to 8
                        set end of List001 to (i * 2) as string
              end repeat
              set myPListFilePath to path to desktop folder from user domain as string
              set fileMyPList to (myPListFilePath & myPListFile) as string
    clear_file(fileMyPList)
    -- First time! need to initalize
              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 new_plistfile to ¬
      make new property list file with properties {contents:parent_dictionary, name:fileMyPList}
      make new property list item at end of property list items of contents of new_plistfile ¬
      with properties {kind:string, name:constPreviousRunDay, value:today}
      make new property list item at end of property list items of contents of new_plistfile ¬
                                  with properties {kind:list, name:"ArrayList001"}
      make new property list item at end of property list items of contents of new_plistfile ¬
                                  with properties {kind:list, name:"ArrayList002"}
              end tell
              set previousRunDate to today
              set xxList to (repopulate_lists())
              set ArrayList001 to List001
              set ArrayList002 to List002
    -- save info in the plist file
              tell application "System Events"
                        tell property list file fileMyPList
                                  tell contents
                                            set value of property list item constPreviousRunDay to previousRunDate
                                            set value of property list item "ArrayList001" to ArrayList001     --   <<< ------- error caused by the statement
                                            set value of property list item "ArrayList002" to ArrayList002
                                  end tell
                        end tell
              end tell
    end run
    -- ==========================================
    on repopulate_lists()
              set newList to {}
              set List002 to {}
              repeat with i from 1 to 8
                        set end of newList to i as string
              end repeat
              set List001 to newList
              return List001
    end repopulate_lists
    -- ==========================================
    -- Does the file exist?
    on fileExists(f)
              try
      f as string as alias
                        return true
              on error errMsg number errNum
                        return false
              end try
    end fileExists
    -- Delete the  files if exist
    on clear_file(aFile)
              if fileExists(aFile) then
                        tell application "Finder"
                                  set resultObject to delete aFile
                        end tell
              end if
    end clear_file

    Here's an AppleScript handler that partially works around this bug (warning: it turns each list item into a string).
    on plistWrite(plistPath, plistItemName, plistItemValue)
      -- version 1.1, Daniel A. Shockley
      -- 1.1 - rough work-around for Mavericks bug where using a list for property list item value wipes out data
              if class of plistItemValue is class of {"a", "b"} and AppleScript version of (system info) as number ≥ 2.3 then
      -- Convert each list item into a string and escape it for the shell command:
      -- This will fail for any data types that AppleScript cannot coerce directly into a string.
                        set plistItemValue_forShell to ""
                        repeat with oneItem in plistItemValue
                                  set plistItemValue_forShell to plistItemValue_forShell & space & quoted form of (oneItem as string)
                        end repeat
                        set shellCommand to "defaults write " & quoted form of POSIX path of plistPath & space & plistItemName & space & "-array" & space & plistItemValue_forShell
      do shell script shellCommand
                        return true
              else -- handle normally, since we aren't dealing with Mavericks list bug:
                        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}
                                  try
                                            set plistFile to property list file plistPath
                                  on error errMsg number errNum
                                            if errNum is -1728 then
                                                      set plistFile to make new property list file with properties {contents:parent_dictionary, name:plistPath}
                                            else
                                                      error errMsg number errNum
                                            end if
                                  end try
                                  tell plistFile
                                            try
                                                      tell property list item plistItemName
                                                                set value to plistItemValue
                                                      end tell
                                            on error errMsg number errNum
                                                      if errNum is -10006 then
      make new property list item at ¬
                                                                          end of property list items of contents of plistFile ¬
      with properties ¬
                                                                          {kind:class of plistItemValue, name:plistItemName, value:plistItemValue}
                                                      else
                                                                error errMsg number errNum
                                                      end if
                                            end try
                                  end tell
                                  return true
                        end tell
              end if
    end plistWrite

  • How to avoid system events "ignoring" lines in applescript?

    Hello!
    I am trying to write a very simple script that will trigger macros on another application, however when the script is executed, it skips a couple of lines which makes the whole process go erratically.
    This is the code i'm using:
    tell application "Adam"
      activate front window
    end tell
    tell application "System Events"
      keystroke "4"
              repeat 10 times
              end repeat
      keystroke return
      keystroke (ASCII character 47)
              keystroke "tell test"
      delay 1
      keystroke return
      keystroke (ASCII character 36)
      keystroke "t"
      keystroke (ASCII character 36)
      delay 2
      keystroke return
    end tell
    The red lines are the ones that seem to be neglected somehow (keystroke "4" doesnt carry the expected action in application "Adam"). I'm a newbie at applescripting but i fail to see why this might be happening
    Any help is of course greatly appreciated

    Hi Arthur!
    Tried your solution without much success, after some playing around i found out changing the command to use any other keystroke (e.g. - ) actually made the script work as intended, although it also implied changing the macro trigger (4 to - ) in application Adam.
    repeat 10 times
    keystroke "-"
    end repeat
    Lately I've been testing with other applications and found out this "ignore" behaviour happens mostly when you use numbers for keystrokes, perhaps there is al alternate way of inputting these?
    Thanks for your and everyone's help

  • I am trying to use automator to open a safari popup window that will automatically log me into whatever account and I attempted to type up an applescript that utilized the "System Events" function with no avail, any ideas?

    I am trying to use automator to open a safari popup window that will automatically log me into whatever account and I attempted to type up an applescript that utilized the "System Events" function with no avail, any ideas?

    Hi
    In iMovie'11 (version 9.0.x)
    on top menu row - Apple/iMovie/File/Edit/Cut (Can vary dep. on language - in Swedish Apple/iMovie/Arkiv/Redigera/Klipp . . . )
    down Cut menu - Slow playback/Raspid Playback/Re-play in Slow Motion and onvards
    Here one can select the Pre-Set speeds
    Are you familiar with getting 'inspector' to run?
    No - but I guess that Double Click on clip/sequense or ctrl-Click on it might open it.
    Yours Bengt W

  • Applescript's System Events forces Mac OS Roman encoding?

    I have written an Applescript which reads the first line of a UTF-8 text file. That string is used to "set value" a particular text area of an IRC client (Textual).
    Unfortunately, any characters not native to Mac OS Roman encoding (unicode-only characters, asian-only glyphs) are substituted for Mac OS Roman characters.
    For example: 
    旦 welcome
      is written into the text area as: 
    Êó¶ welcome
    How can I force the text back into UTF-8 encoding, or fix this issue?
    my script:
    set source to "/Users/admin/Documents/file.txt" --UTF-8 file
    set N to paragraphs of (read POSIX file source)
    set phrase to first item of N
    tell application "Textual" --IRC client
    activate
    tell application "System Events"
        delay 0.3
        set value of text area 1 of scroll area 1 of window 1 of process "Textual" to phrase
        --the main text entry field of this application
        keystroke return
    end tell
    end tell

    Nothing is "forced"; how a file is read is determined by your system's language settings - for English, this is usuallly MacRoman.  To read in a different encoding, use the read command's as parameter to specify, for example:
        read POSIX file source as «class utf8»

  • AppleScript Performance Difference from Finder to System Events

    I've just made an interesting discovery. I have a folder that contains about 7000 other folders. When I use the code "tell application "Finder" to set folder_list to folders in folder base_folder" it takes a very long time to respond, about 40 seconds. When I use the code "tell application "System Events" to set folder_list to every folder of folder base_folder" to seems to produce the same result in only about 2 seconds. If I add the filtering criteria, like "whose name begins with search_name", the performance difference is even greater. Clearly I'll be using System Events from now on, but can anyone explain why there is such a large difference in performance? Is there anywhere I can find other performance tweaks like this?
    Note, I'm using system 10.6.5, but there is no automator section in that forum.

    It seems you're going in panic!
    First of all run mainteinance , look for system updates if any, and take care of any block key pressed
    on your keyboard.
    Do not abuse of Force Quit it 'd destroy preference applications, if your itunes take 3h to import your library you can setup in Energy Saver panel some tunings to protect lcd.
    I think 3h to import a music library is not normal, can you post some other info about?
    What can of device you are copying from?
    Did you import ,when you set up your new iMac , an user from your old mac?
    Take a look also at spotlight corner, if there's a little point inside the glass icon , spotlight is indexing your drive/s , this is normal on the first system's run and this 'd slow mac performance.

  • System Events startup problem

    Recently I noticed my Macbooks fans where spinning all the time for no apparent reason.
    Upon further investigation I found out every single time I reboot my Macbook an application titled "System Events" will use up 50-60% of my CPU (continuously) until I force quit it from within the Activity Monitor and after this it will happily idle at around 3% presumably doing what ever task it does.
    I didn’t want to outright delete the application as I have no idea what it does and its also inside a folder labeled "Core Services", seemed like an area to tread carefully within.
    At least I have found a relatively simple work around but I was wondering if there is anyway to stop this happening all together?
    So far I've tried to disable each application that is being loaded on startup one at time to see if its any of them, Ive also tried adding and deleting the offending System Events application from the startup applications.
    Ive had no luck so far so any help will be much appreciated, if you need any further information on my Macbook I will be more than happy to provide it.
    Thanks for reading.
    EDIT: Ive also tried leaving the Macbook running while I was at work for around 6 hours, when I came home System Events was still at 60%, the logic behind doing this was to see if it was doing some sort of task system wide and I wasn’t giving it enough time to execute.
    Also these are the current applications running on startup.
    Quote:
    Ruby:~ Juo$ defaults read loginwindow | grep Path
    Path = "/Applications/iTunes.app/Contents/Resources/iTunesHelper.app";
    Path = "/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app" ;
    Path = "/Applications/Quicksilver.app";
    Path = "/Users/juo/Library/PreferencePanes/SynergyKM.prefPane/Contents/Resources/Syner gyd.app";
    Path = "/Applications/Colloquy.app";
    Path = "/Applications/Google Notifier.app";
    Path = "/Users/juo/Library/PreferencePanes/BusySync.prefPane/Contents/Resources/BusySy nc.app";
    Path = "/Volumes/Juo";
    Path = "/Applications/Adium.app";
    Path = "/Applications/Twitterrific.app";
    Path = "/Users/juo/Library/PreferencePanes/GrabUp.prefPane/Contents/Resources/GrabUpDa emon.app";
    Path = "/Users/juo/Library/PreferencePanes/GeekTool.prefPane/Contents/Resources/GeekTo ol.app";
    Path = "/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlMenu.app";
    Finally I am running Leopard 10.5.2 and have all the latest updates available within "Software Update"

    Welcome to the forums!
    "System Events" is widely used by AppleScript and by apps using AppleScript. Do NOT touch the app itself. You can certainly remove it from Login Items without making a scrap of difference - it will simply take a fraction of a second longer for the calling app to use it.
    IMO, you are going about things the right way. I am, in fact, surprised that one of those items you list is not the culprit. The culprit is most likely to be something in your Login Items or in /Library/StartupItems. You can ascertain which by logging into another, clean, account - create a temporary one if you don't have one. That will immediately tell you if the problem is limited to your account or is global.
    Tell us whether the problem is global or not, and that there is no doubt that you have exonerated the above items, and one of us will tell you where to look next.

  • System Events keeps crashing

    First of all, forgive me if there is a more appropriate category for this to be posted in. I couldn't think of anything better suited to this exact issue.
    On every boot, OS X brings up a standard "Application quit unexpectedly" dialogue for System Events. I can simply close this and disregard it, and it does not affect operation in any way.
    However, just recently I have found that when I attempt to launch Adium, the open-source IM client, it hangs for a good deal of time and then brings up the same dialogue. Adium, in the end, is unable to start and must be forcefully terminated.
    I was wondering if there might be any relation between the two occurrences. I do not know exactly what System Events is responsible for, and if someone could enlighten me, perhaps I could go about fixing the annoyance at startup, and possibly the problem with Adium at the same time.
    Thanks in advance.
    Oh, another note: both problems started very recently, at least one of them around the time I updated to 10.4.11.

    You can certainly remove System Events from Login Items, and I suggest you do. It serves no useful purpose by being launched independently in that way. It will be 'called' (transparently) by an AppleScript (or something similar) as and when needed. The time penalty for it not already running will be indiscernible.
    However, sorry to tell you, but removing it as a login item is unlikely to make a scrap of difference to anything. Having System Events made to run in that way is unnecessary but should not be harmful in any way: it just runs consuming no CPU, only being used when 'called' by an app, and it is the app that is doing the calling that I would suspect. Did you also check /Library/StartupItems?
    There is the remote (very remote) possibility that System Events.app itself is corrupted. You can easily check that. Launch Script Editor (in /Applications/AppleScript), paste this line:
    tell app "System Events" to say "Hello Benjamin"
    Hit <Enter>. The line should format (the text will change its appearance) without error; then hit the 'Run' button. If, as I expect, that causes no error, you are condemned to carry on playing "hunt the app".
    Does the error message appear when you log into another account? (Create a temporary account if needed, and then delete it).

  • Javascript to set slider value with System Events

    If I open System Preferences and run this in Script Editor, it fails. It sets the volume to zero, not 50%.
      var se = Application("System Events");
      var spp = se.processes["System Preferences"];
      var curr = spp.windows[0].sliders[0].value();
      console.log("Current value: " + curr + " - " + typeof(curr));
      spp.windows[0].sliders[0].value = 0.5
      var curr = spp.windows[0].sliders[0].value();
      console.log("Current value: " + curr + " - " + typeof(curr));
    But the same thing in AppleScript seems to work fine.
    tell application "System Events"
       tell process "System Preferences"
       set v to value of slider 0 of window 0
       log v
       set value of slider 0 of window 0 to 0.5
       end tell
    end tell
    Anyone know what the problem is?
    thanks,
    Rob

    Jon Handy wrote:
    Hello,
    You should use something like this within the link attribute for that report column.
    onClick="javascript:setItem('P48_RECEIPT_ID',#RECEIPT_ID#);"As noted above, it is not considered good practice in this forum to post unnecessary follow-ups to long expired threads and users. It's worse to do so with information that is inaccurate or incomplete.
    What is the purpose of <tt>javascript:</tt> in this code?
    What is <tt>setItem</tt>? It is not a standard APEX JavaScript API method.
    You're welcome to get involved in the forum, but why make your first post an inaccurate response to a random 6 month old post that is only one of hundreds/thousands of questions on setting an item value using JavaScript?

  • Acrobat pro and system events

    Hi,
    I want to make some changes in the properties of a row of pdf's. I want to change the magnification and page layout. I only know a bit of applescript. Yes I know it isn't Javascript but I didn't find a place for applescript, I am sorry..
    this is what I've got:
    tell application "System Events"
       tell process "Acrobat"
           activate
           tell menu bar 1
               tell menu bar item "File"
                   tell menu "File"
                       click menu item "Properties..."
                       tell window "Properties…" of process "Acrobat"
                       end tell
                   end tell
               end tell
           end tell
       end tell
    end tell
    I can't set the magnification to "fit page" and page layout to (two up cover page)
    Who can help me please?

    Acrobat forms only run Acrobat JavaScirpt within the form. You can use Apple Script and the Acrobat API to access the JavaScripts within a PDF or run some JavaScript within  a PDF.

  • Startup error message:System Events got an error: NSInternalScriptError (8)

    I just upgraded from Panther to Tiger on my mac Mini and I can't seem to get rid of this message everytime I boot up:
    System Events got an error: NSInternalScriptError (8)
    Any idea how I can "fix" this?
    Much thanks.

    Do you have any login items listed in the Accounts pane of your System Preferences? If so, disable them and restart to see if that clears the message. If so, then re-enable them one by one and restart to see which one it is.
    In doing a Google search, that message appears to come from an AppleScript. So perhaps you have an AppleScript running at login that needs to be modified to be compatible with Tiger...
    charlie

  • IMovie crashes when event deleted or renamed. Events were moved to Disk C.

    I have a problem that has stumped me, the phone Mac Genius, and my local store Genius. iMovie '09 worked well for me but System drive A was getting too full. I moved both the iMovie Project and Event Folders to a separate internal hard drive. I did not do it within the iMovie program itself. I simply copied the folders and deleted the originals. Somewhere in there I upgraded to Snow Leopard but that may be unrelated. Things seemed to work fine until I tried to rename an Event, delete an event, or discard rejected clips. If I do those things, iMovie crashes without making the changes. It deposits some files in the trash in the effort. I can rename or delete a project OK. I can still import, edit, and share movies seemingly normally.
    I notice that when I create a DVD in iDVD, that all my iMovies appear twice in the Media Browser, one full set after the other.
    I tried all the usual things. Deleted all the preference files that I could find. Reinstalled iMovie. Reinstalled Snow Leopard. Even did an erase and clean reinstall of Snow Leopard and iLife '09 on my drive A. Switched drives B and C. Problem persists.
    If I import a small clip from my Flip Camera to Drive A, I cannot change name or delete. If I remove Drive C with all my video (500 GB+) from its bay, then I can change name and delete the events on Drive A.
    Seems to me there is some registry information within the event or project files that I scrambled when I moved them to another internal hard drive. Was there some other way I should have tried? What happened and how can I recover?

    Same problem for me too. If you look at the top section of your crash report you see reference to 3ivx, this is some kind of video codec. I did a search on my mac for 3ivx and uninstalled it. This fixed the problem. See these two articles for more information:
    http://forums.appleinsider.com/t/150648/imovie-crashed-after-osx-update-from-6-1 2-2012
    http://linvsmac.blogspot.com/2012/07/imovie-906-upgrade-conflicts-with-3ivx.html
    Hope this helps.

  • Retrieve duration of sound files via Apple Script - System Events

    I need to get more details of my sound files into a FileMaker 10 Database as it is possible by using the FileMaker import function. There ist a complicated way by going first through iTunes and than to FileMaker. Now I found out, that part of the information displayed when pushing cmd+i can be retrieved with this:
    tell application "System Events"
    properties of file "/Volumes/MacHD/singsong.mp3"
    end tell.
    But duration, channels, bitrate are not accessible. Is this a general problem with metadata? May be if I got a hint how to retrieve meta-data from .jpg files I might be able to apply this also on .mp3

    Try the AppleScript forum under OS X Technologies.

Maybe you are looking for

  • Statistics of Sync and Async messages in PI

    Hi, How can we count no of Sync and Async messages that were processed(sucessful or unsucessful) in PI. Does the worbench has any table or Report that will give me the statistics. Request some pointers on the same. Thanks , Bhanu.

  • How to create a Url assembler in Webcentre for creating friendly url?

    Hi, To create a URL Assembler I am required to code a java class  that extends the com.fatwire.cs.core.uri.QueryAssembler class. The friendly URL of a Page will be based on the "Friendly_URL" attribute Rule to generate the final URL URL starts with {

  • Problem installing extension in DW MX2004 mac edition

    Hi all, I run DW MX2004 under OS X 10.4.10 on a Mac. I'm having trouble installing the Rubyweaver 2.0 extension (available from http://rubyweaver.gilluminate.com/) which should add ruby and rails functionality to DW. According to Extension Manager it

  • Missing messages - sorta

    Hi all, Been scratching my head over this for a while but can't seem to find info about these symptoms: - I seem to remember re-naming an account, then losing the ability to display any message content. The headers were all there in the mail message

  • URGENT! ArrayIndexOutOfBoundsException in Extended "EO based" VO

    Hi! This is weird! I am extending a VO (xxPorInfoTemplatesVO) and I am populating it in another extended VO (xxPoRequisitionLinesVO). In the extended xxPorInfoTemplatesVO I Have added 3 more attributes based on EO (Attribute1, Attribue2 and Attribute