Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4084700
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:28:25+00:00 2026-05-20T18:28:25+00:00

I was wondering if there is a way to programmatically empty the contents of

  • 0

I was wondering if there is a way to programmatically empty the contents of the trash bin. I’m currently deleting files that are located there using:

    NSFileManager *manager = [NSFileManager defaultManager];
    [manager removeItemAtPath:fileToDelete error:nil];

However, after I use this operation, every time I drag a file to the trash, I am prompted with the message:

Are you sure you want to delete
“xxxxxx.xxx”?This item will be deleted
immediately. You can’t undo this
action.

This lasts until I either log out or sudo rm -rf the trash bin.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:28:25+00:00Added an answer on May 20, 2026 at 6:28 pm

    You can put stuff in the trash with NSWorkspace, however deleting the trash is kind of a no no for programs so you aren’t going to find an API. So your best bet is using the ScriptBridge.

    Add ScriptingBridge.framework to your build target, and generate a header file for Finder using:

    sdef /System/Library/CoreServices/Finder.app/ | sdp -fh --basename Finder
    

    Then you can ask Finder to prompt the user to empty the trash:

    #import "Finder.h"
    
    FinderApplication *finder = [SBApplication applicationWithBundleIdentifier:@"com.apple.Finder"];
    
    // activate finder
    [finder activate];
    
    // wait a moment (activate is not instant), then present alert message
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
      [finder emptySecurity:security];
    });
    

    See the Scripting Bridge documentation for more details.


    As of Xcode 7.3, if you attempt this with Swift you will get linker errors trying to find classes defined in Finder.h. So you’ll have to create an Objective-C wrapper.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is about memory use and objects in actionscript 2. If I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.