Help - AppleScript to delete empty folders

I have been trying to create an AppleScript that will let me clean directories of empty folders. I have scoured the web and developed the following script. It doesn't work. I have a simpler script but it requires that I enter my admin password everytime that a folder is identified to delete. I'm trying to develop something that only requires me to enter the admin password once. Can someone help me identify the problem with this script?
on killEmpty(fol)
  tell application "Finder"
  repeat with f in (get fol's folders)
  my killEmpty(f)
  end repeat
  if (count items of fol) is 0 then do shell script "rmdir" with administrator privileges
  end tell
end killEmpty
tell application "Finder"
  repeat with f in (get folders of window 1)
  my killEmpty(f)
  end repeat
endtell

Hi,
If you need an administrator's password, use a command in a do shell script to find and delete all empty folders, like this script:
tell application "Finder" to set tDir to quoted form of POSIX path of the ((target of Finder window 1) as string)
set pScript to quoted form of "from os import walk; from sys import argv; from shutil import rmtree; import glob
for dirpath, _, _ in walk(argv[1], topdown=False):
    if not (glob.glob(dirpath + '/*')): rmtree(dirpath)"
do shell script "/usr/bin/python -c " & pScript & " " & tDir with administrator privileges

Similar Messages

  • Deleting Empty Folders from Library

    When I first got Lightroom I uploaded a random bunch of folders of images. Now I wish to upload everything (which I have put into a single folder) so that I can retain the hierarchy of folders within folders that I have developed for storing my work on a dedicated hard drive.
    I therefore selected all of these random folders of images and removed them from the Library (it took 45 minutes). But now I find that while all of the image files have been removed, all of the empty folders that contained them are left in the "Folders" folder in the library.
    My question is, how can I remove all of these empty folders prior to uploading my hierarchical folders of files? In other words, how can I start over again from scratch? (I have upgraded to Lightroom 1.1)
    Thank you.

    Thank you all for your suggestions. What I finally did was to right-click, as suggested by Mel, on each folder (it wouldn't work for me when I selected them all) and select "delete" from the resulting drop-down menu. It took awhile, as there were a lot of the buggers, but now I'm clean and ready to go!
    Again, thanks.
    Rodger

  • Can't delete empty folders from NAS

    Hi all
    I have Mac Book Pro running Mavericks, and a WD World Book running as a NAS on my private network.
    Recently, I've been restructuring my files and folders on both my mac and hard drive.
    Having moved a large number of files across from the HD to my Mac, I now have a load of empty folders on my HD that I cannot seem to get rid of!
    I have tried all the usual things, and also the rm -r command but to no avail. It says that the folder does not exist!
    One other strange thing that is happening on the HD, when I 'Get Info', the top username in permissions is just saying 'fetching' and never resolves.
    Does anyone have any suggestions??
    Let me know if you need more info
    Thanks in advance

    Yes, it one of the problems you can encounter using Launchpad at the moment. You can try to drag another app in the folder and empty the folder again. Sometimes that folder disappears, sometimes not.
    There's a way to rebuild Launchpad but I won't not recommend that. It will bring Launchpad back in the default-setting, so you would have to start rearranging all over again, at the risk of having the same problems all over again.
    So, just wait until the first update of Yosemite comes out. That might solve your problem. If the empty folders bother you, you could try to drag them to a new last page, so they are out of sight for now.

  • Applescript for deleting user folders

    Hi,
    So I am managing a group of about 80+ iMacs and an Xserve.  I would like to delete the contents of the users folder excluding the arduser (user i will be using to run script), shared folder and a desktop alias file.  I want to be able to connect to the server from computer im wiping click on the script and have it run without having to choose folders and click extra things, just double click and done.  Ideally I would like this script to do much more, such as delete all cs3, 4, 5 apps and a couple of app folders all in one swoop.  Would love some help, I am new to Applescripts and am unfamiliar witht the language.
    Thanks

    I'm not sure I understand this. Why would you log into the server to wipe the users on the local machine? Why not wipe them from the local machine directly?
    In any case, this is better accomplished with bash rather than AppleScript.
    Suppose you have a user account called 'John' on the local machine. You'd use
    sudo rm -rf /Users/John/*
    and that would wipe out everything in the users account, but leave the parent directory 'John' in place (and empty).
    The next time you log in to user 'John' on that machine, the OS will recreate default System folders (Desktop, Documents, Downloads, Library, Movies, Music & Pictures).

  • Deleting empty folders

    I am trying to delete an empty folder from Robohelp. I've had
    this problem before & resolved it following some advice from
    this forum. The problem this time seems to be a file called
    ehlpdhtm.js (found in the Baggage folder). The instructions I got
    before said to remove all references to this file. The problem is:
    this file is in the code for every single topic I have. So I don't
    know what to do to fix it. I have 13,000 topics in my help file so
    there's no way I can remove it from all of them. Any suggestions?
    thanks!
    C

    The ehlpdhtm.js file is added to each topic regardless of
    whether the topic actually needs it. It contains dynamic HTML code
    (e.g. drop down or expanding text). If your topics do not contain
    any dynamic HTML then it is probably safe to remove the file from
    baggage. If you can't do this from within RH, open the rhbag.apj
    file in Notepad and remove it there. I recommend the usual advice
    about taking backups before doing anything though.

  • How to delete empty folders on iPod Touch iOS 4.2.1?

    I just updated my iPod Touch 2gen to 4.2.1 and while organizing the apps via iTunes, it kept creating folders named 'Games' and 'New Folder.' How the heck do I delete these? They're empty, I've tried rebooting my iPod and I've tried putting in apps and emptying them again.

    When a folder is empty it should automatically delete itself.
    try restarting it by holding the lock and middle button, together for 10 seconds
    Kayley Anne

  • Help - Applescript to Delete Calendar

    I need to find an applescript or automator sequence to delete a calendar from iCal.
    The calendar to be deleted would always have the same name.
    Could use some help here.
    Thanks in advance.

    John,
    Really appreciate your help. This is a nice script you have done.
    I put the delete / create up front. I find that whatever name I use, the new calendar created is "untitled" so I am just using that.
    Anyway, I just want SourceCal to be "untitled" and
    myfile to be Calendar Export.txt from my documents folder
    Thanks.
    Rex
    tell application "iCal" to delete calendar "untitled"
    tell application "iCal" to create calendar "untitled"
    tell application "iCal"
    set sourceCal to first calendar whose name is (item 1 of (choose from list (name of (every calendar) as list) with prompt "Choose calendar to add events to."))
    set myFile to choose file with prompt "Where is the exported Now Up To Date file?"
    end tell
    set myEvents to paragraphs of (read myFile)
    set myNow to current date
    repeat with thisEvent in myEvents
    set {myTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {tab}}
    set eventDetails to text items of thisEvent
    set AppleScript's text item delimiters to myTIDs
    if (count of eventDetails) is greater than 1 then
    set anEvent to false
    set allDay to false
    if item 2 of eventDetails is not equal to "" then
    set thisStart to date (item 1 of eventDetails & " " & item 2 of eventDetails)
    set thisEnd to date (item 1 of eventDetails & " " & item 3 of eventDetails)
    set anEvent to true
    else
    set thisStart to date (item 1 of eventDetails)
    if item 6 of eventDetails contains "All Day" or item 6 of eventDetails contains "Banner" then
    set thisEnd to (date (item 1 of eventDetails)) + 1 * days
    set allDay to true
    set anEvent to true
    end if
    end if
    set mySummary to (item 4 of eventDetails)
    set {myTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {ASCII character 11}}
    set (item 5 of eventDetails) to text items of (item 5 of eventDetails)
    set AppleScript's text item delimiters to {return}
    set (item 5 of eventDetails) to (item 5 of eventDetails) as text
    set AppleScript's text item delimiters to myTIDs
    set myDescription to "CATEGORY: " & (item 8 of eventDetails) & return & "TYPE: " & (item 6 of eventDetails) & return & "PRIORITY: " & (item 7 of eventDetails) & return & (item 5 of eventDetails)
    set doneFlag to false
    if (item 10 of eventDetails) is equal to "Done" then set doneFlag to true
    tell application "iCal"
    if anEvent is true then
    set newEvent to make new event at the end of events of sourceCal with properties {summary:mySummary, description:myDescription, start date:thisStart, end date:thisEnd}
    if allDay is true then
    set allday event of newEvent to true
    else
    set end date of newEvent to thisEnd
    end if
    else
    set newToDo to make new todo at the end of todos of sourceCal with properties {summary:mySummary, description:myDescription, due date:thisStart}
    if doneFlag is true then
    set completion date of newToDo to myNow
    end if
    end if
    end tell
    end if
    end repeat
    tell application "iCal" to display dialog "events added in " & (current date) - myNow & " seconds."

  • Empty folders cannot be deleted in launchpad

    It seems it has become impossible to delete empty folders in the launchpad or in dashboard's widgets. Anyone having this problem too? How to resolve it?

    Just Relaunch your Launchpad
    Open Terminal
    Copy and paste this commands on your terminal and hit return at the end of each line
    defaults write com.apple.dock ResetLaunchPad -bool true
    killall Dock
    hope that helps,
    05202

  • I have 40 empty folders in my mailbox on ipad 3. They are shown on the left hand side of my mailbox screen.I have tried to delete them but they keep re appearing should they be there or can anyone tell me how to delete them. .

    I have 40 empty folders which have appeared in my mailbox. I have tried to delete them using the edit button but they keep coming back. I have done a factory reset to start my ipad as new but this has not removed them. They have now appeared on my wifes ipad air. Can anyone help please.

    Hi Go to Settings Email Accounts Delete Accounts Then add them back again. If that doesn't work Do a Factory Restore. Cheers Brian

  • Help - I am unable to delete 2 folders from the trash in Mac OS X Lion

    Help - I am unable to delete two folders (one inside the other) and it seems to be playing havoc with my Finder.
    Can anyone advise on how I remove these?
    Thanks.

    Hey Dawg,
    check this out...
    http://osxdaily.com/2012/07/19/force-empty-trash-in-mac-os-x-when-file-is-locked -or-in-use/

  • Can anyone help me with deleting folders from Appleworks?

    I have an older computer that I am giving to a friend and I want to export and remove all of my personal folders in Appleworks (6.2.9). I have not been able to export info and I have also not been able to delete any folders from Appleworks. I can delete all the info in the individual file (ss or wp) but cannot remove the file itself. I don't know what I'm missing but I cannot find info on how to handle this problem. Can anyone help me with this?

    Search for the file's name in the Finder, throw it away, and empty the Trash; the Finder is the item in the Dock with the smiling face.
    (38373)

  • Help I have put lock folders from time machine in the trash and now I can not empty the trash of these folders

    Help I have put some folders from timemachine in the trash and now I can not empty the trash can.  I now realised I took the wrong action to delete these folders duh! but i canot work out how to solve the problem I now have, can anybody please tell me what action to take?

    Hi Linc
    Thank you for your reply.  It did not work at first, I think there was just to much stuff.  In frustration I held ctlr, alt and cmd keys down then empted the trash and it worked!  I had to repeat the process several times as only a few folders were delt with at a time. but now are all gone.
    Kind regards Dian

  • My itunes will not work at all. i have deleted and reinstalled in over ten times, i have ended the process, i have reinstalled quicktime i few times, i have deleted many folders. What else can i do? Please help:(

    My itunes will not work at all. i have deleted and reinstalled in over ten times, i have ended the process, i have reinstalled quicktime i few times, i have deleted many folders such as TEMP, itunes helper et What else can i do? Please help:(

    Now it sometimes keeps coming up and working but once i plug an ipod in it freezes my whole computer up and no i dont get any response from itunes at all

  • Delete Empty Frames in Indesign through AppleScript

    Hi Everyone,
    We have some users who mistakenly add empty frames in the indesign document. (these are generally very small for example {4.9786 in, 3.9402 in} etc)
    Can we identify such frames through an apple script.
    Usually the frames can be made as a text frame, graphics or unassigned. I am able to delete the empty text frames by using below code:
    tell application "InDesign CS4"
    tell page 1 of document 1
    delete every text frame whose contents is ""
    end tell
    end tell
    However, not sure how to delete empty graphics or unassigned frames.
    Appreciate your help and suggestions!
    Thanks,
    Abhi

    You could check the rectangle for graphic 1 and check the rectangle for its content type. Something like:
    tell application "Adobe InDesign CS4"
              tell document 1
                        tell page 1
                                  tell rectangle 1
      display dialog (content type as text) --> "unassigned" or "graphic type"
                                            if exists graphic 1 then
                                                      display dialog ("There is a graphic in this rectangle.")
                                            else
                                                      display dialog ("There is no graphic in this rectangle.")
                                            end if
                                  end tell
                        end tell
              end tell
    end tell

  • I am anew user. Initially I created several folders for my photos but now know how to transfer photo folders using iTunes. However I am unable to delete/remove the now empty folders I created in iPad.

    I am anew user.
    Initially I created several folders for my photos on the iPad itself but now know how to transfer photo folders using iTunes. However I am unable to delete/remove the now empty folders I created in iPad.
    Can anyone assist me please
    Thanks

    When you are in Album view in the Photos app - tap the edit button in the upper right corner - tap the X in the corner of the album to delete it.

Maybe you are looking for

  • Additional field required in CIN  master data

    Dear All, In Vendor Master CIN details - Service Tax Registration Number field exist. we require one additional field for catogary of service of vendor for capturing thro' category.Please let us know how to provide one additional field to capture ven

  • PROFIT & LOSS ACCOUNT CONFIGURATION

    Hi all....... I want to create Profit & Loss A/C. Through FSV I have created Balance Sheet. Can anyone please help me regarding the configuration steps of Profit & Loss A/C. Best Regards Amitava Saha Moderator: Please, avoid asking basic questions an

  • BPA Help please...Urgent !

    Hi all... I have now been asked to prepare the business case for BPM. A quick couple of questions if I may * What platform does BPM run on??? * I assume it's an Oracle database?? * Can it co exist alongside other oracle products or does it need separ

  • DIR creation in easyDMS through template

    Hi, Is there anyway to create DIR in easyDMS through template. Thanks. Anirudh,

  • Swf files misdisplayed if contain filter

    If you create a file in Flash using a movieclip symbol and apply to it a filter, then export in swf format to use it in Director, when you insert the swf in the stage of Director and set for this sprite the ink to background transparent, the swf is m