• 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: Need help writing some AppleScripts!!! Please help!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help writing some AppleScripts!!! Please help!


  • Subject: Re: Need help writing some AppleScripts!!! Please help!
  • From: David Nelson <email@hidden>
  • Date: Fri, 17 May 2002 15:05:49 -0500

On Friday, May 17, 2002, at 06:50 AM, Dan Ball wrote:

1) How do I have an AppleScript automatically click a button on a dialog
box?? Say I get an error that I know is going to happen with a script and
instead of waiting for the user to select the button I want the script to
select it automatically! Possible?

AppleScript does not have the ability to click buttons built in, however this functionality can be added via a Scripting Addition. Check <http://www.osaxen.com/>. Another good site for scripting info is: <http://www.osaxen.com/>

Give us a more detailed description of what the script in question does and maybe someone can help. When posting help requests it helps to describe exactly what you are trying to accomplish with your script. Often there is more than one way to get the job done with AppleScript. If people know exactly what you want to do and not just the problem you are having they might be able to suggest a solution that avoids the problem all together instead of just working around it. BTW also let us know if you are using Mac OS 9 or 10.

2) I want an AppleScript to keep the desktops clean, I have three items on
the desktop: Macintosh HD, a printer named Accel-a-Writer 3G Pool, and an
alias going to the Launcher.
How do I write a script to delete everything on the Desktop no matter what
they are except these three items?

This one is very do-able and something I recall trying to do when I first started scripting. Here is a script that will do the job:
-- BEGIN APPLESCRIPT ClearDesktopClutter
-- Desktop items to leave in place. Disks will be skipped by default so no need to list them here.
set exclusionList to {"Accel-a-Writer 3G Pool", "Launcher"}

tell application "Finder"
-- Get a list of alias references to all the stuff on the desktop.
set desktopItems to every item of desktop as alias list

-- Loop through all the alias references in the list desktopItems adding those
-- that are not found in the list exclusionList and whose kind is not Volume to a
-- new list called desktopClutter.
set desktopClutter to {}
repeat with i in desktopItems
if ((name of contents of i) is not in exclusionList) and ((kind of contents of i) is not "Volume") then
set desktopClutter to (desktopClutter & contents of i)
end if
end repeat


-- At this point we could just issue the command delete desktopClutter and be done. I however felt the need
-- to have this script display a dialog telling the user how many items were found cluttering the
-- desktop and offer a chance to cancel the script and not delete them. The script displays the
-- dialog if one or more clutter items are found. If no items are found there is nothing for the
-- script to do so it just exits.
set clutterCount to (count desktopClutter)
if (clutterCount is greater than or equal to 1) then

-- This foolishness lets my dialog be grammaticly correct wether there is a single or
-- multiple clutter items found.
if clutterCount is 1 then
set maybeS to ""
set wasWere to "was"
else
set maybeS to "s"
set wasWere to "were"
end if

activate -- brings the Finder to the forground so you can see my fancy dialog box.
display dialog (clutterCount & " item" & maybeS & " " & wasWere & " found cluttering your desktop. Delete the clutter?") as text

-- Now that we know we are going to delete all this stuff we loop through it again
-- and make sure none of the files are locked. Note: I don't bother to check if the files
-- are locked or not. In this case it's simpler and faster just to hit each file with an unlock
-- command and not worry that most of the time none of the files will be locked.
repeat with i in desktopClutter
set locked of contents of i to false
end repeat

-- Move all the clutter to the trash.
delete desktopClutter

-- I left the final statement commented out as it empties the trash which could of course result in
-- the loss of data. I would suggest never uncommenting this since I belive it is better to have a
-- bunch of stuff sitting in your trash all the time than to take a chance on deleting something
-- you did not intened to delete. Anyhow if you decide to uncomment this at least wait until you
-- have tested the script and are sure everthing you don't want trashed is in the exclusionList.
-- empty trash without warning
end if

end tell
-- END APPLESCRIPT ClearDesktopClutter


3) How do I have an AppleScript empty the trash if items are locked?

I discovered while writing this script that the delete command which actually just moves items to the trash will return an error if used on a locked item. In this script I got around this by unlocking everything before moving it to the trash.

Hope this helps and that no one is ticked off that I posted such a long message to the list.

Have a great day.
David Nelson
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Need help writing some AppleScripts!!! Please help!
      • From: Christopher Nebel <email@hidden>
    • Tex-edit + iListen scripting
      • From: "©" <email@hidden>
References: 
 >Need help writing some AppleScripts!!! Please help! (From: Dan Ball <email@hidden>)

  • Prev by Date: Re: text offset slow in quark 4.11
  • Next by Date: Re: text offset slow in quark 4.11
  • Previous by thread: Re: Need help writing some AppleScripts!!! Please help!
  • Next by thread: Tex-edit + iListen scripting
  • Index(es):
    • Date
    • Thread