• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: VERY NOOB help!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: VERY NOOB help!


  • Subject: Re: VERY NOOB help!
  • From: Marc Glasgow <email@hidden>
  • Date: Sun, 02 Nov 2008 01:50:04 -0400

Since we can't see the code, it's hard to diagnose. Copying the code directly to the body of the email will ensure that it gets through.

In my experiences moving files and subsequently emptying the trash, there can be timing issues that can be better handled by using two separate tell "Finder" statements -- the first to move all the files, and then a second one after it to empty the trash.

Here's a code example that I use to move just gif & bmp files to the trash that might provide some insight (it's not the most streamlined code in the universe in terms of selecting those file types, but it works in a way that should be clear to you):


tell application "Finder"

-- take the current finder highlighted selection
set OurList to selection
set OurNewList to selection

-- check to make sure there was something highlighted
if OurList = {} then

-- if no files are selected when script is run, beep and skip to end
beep

else -- if there is actually something selected

try
-- the following only works if more than 1 thing selected, since an empty list is already ruled out above
set OurList to selection as alias list

on error
-- thus, if there's only 1 selection, use this instead
set OurItem to selection as alias
-- and coerce it into being the list we want
set OurList to {OurItem} as list
end try

set SecondIndexCounter to 0 as integer -- initialize the counter for our replacement selection list

-------------------------------------------------------------
-- We now have a list built, called OurList, which contains everything selected, including their paths...
-- if nothing was selected, then this part would have been skipped
-------------------------------------------------------------


-- Start looping through the selected files
set SelectionCount to the number of items in OurList
repeat with GenericLoopCounter from 1 to SelectionCount

-- check the file type to ensure it's the right filetype(s) we're working with
set LocalPointerCopy to ((item GenericLoopCounter of OurList) as string) as string
set File_Ext to (characters -4 thru end of LocalPointerCopy) as string
if ((File_Ext = ".gif") or (File_Ext = ".GIF") or (File_Ext = ".bmp") or (File_Ext = ".BMP")) then
set SecondIndexCounter to SecondIndexCounter + 1
set item SecondIndexCounter of OurNewList to (item GenericLoopCounter of OurList)
end if -- if file is of type ".gif" or ".GIF"

end repeat -- ends cycling through the list of the selected files

end if -- if nothing selected (beep) /somthing (do it) selected

if SecondIndexCounter > 0 then
-- trim the new list to just the correct file entries
set selection to items 1 thru SecondIndexCounter of OurNewList
try
move selection to trash
on error
display dialog "problem moving files to trash can"
end try
end if
end tell -- end first Finder tell statement (select & move files)


tell application "Finder"
	empty the trash
end tell

Cheers,
=-= Marc Glasgow

On Nov 1, 2008, at 6:08 PM, email@hidden wrote:
I have no previous coding skill and have tried to read through the
overwhelming sites that are available.

I have written a workflow that runs a short script. It is attached.

The workflow is supposed to grab all files and folders in the
"downloads" folder, move them to the trash, then empty the trash of
those files. A very general grab, move, delete.

The workflow works perfect when automator is open and running. After I
save it as an application and run it, It takes out the trash but
doesn't move any files. What did I miss?

-------------- next part --------------
A non-text attachment was scrubbed...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Prev by Date: Did anyone try to script Bento 2?
  • Next by Date: Re: Did anyone try to script Bento 2?
  • Previous by thread: Re: VERY NOOB help!
  • Next by thread: Re: VERY NOOB help!
  • Index(es):
    • Date
    • Thread