Make the simplest MAC software – show/hide files

As a Developer using a MAC, we all know that the MAC system is concerned about privacy protection, so it is basically impossible for ordinary people to open hidden files. As iOS developers, we have to access hidden files. At this point we only have to use the terminal to enter commands and the commands themselves to show and hide files are not particularly complicated

defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder


defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder
Copy the code

Two simple lines. If you look at one of them individually, it means very simple: Open/hide file permissions, restart Finder

Since we’re iOS developers, can we create our own MAC app that shows and hides files with one click? Of course you can! In addition, we can also create quick services, etc., of course, I will not introduce…

We don’t have much to prepare, just those two lines of command

Ok, using Xcode to create a MAC project, we see a different interface

Let’s change the window size and vc size, add two buttons and create corresponding click events

[[NSTask launchedTaskWithLaunchPath:@"/bin/sh"
                              arguments:@[@"-c"The @"defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder"]]
     waitUntilExit];
Copy the code
[[NSTask launchedTaskWithLaunchPath:@"/bin/sh"
                              arguments:@[@"-c"The @"defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder"]]
     waitUntilExit];
Copy the code

OK, run the software and see?

Ok, now that we have a basic show/hide app, we can imitate iOS development, add app ICONS, and of course we can explore the menu bar

OK, this tutorial is a basic introduction to MAC development. Let iOS developers MAC development also more interested in, actually the development difference is not big, but at different environment, the control is different, but the overall development process of the basic are the same, if you are interested in MAC development, you might as well try, online MAC development tutorial relatively may be a little less, but as long as you want to learn, still can find a lot of information. . Of course, this blog is just a little DEMO that you can continue to optimize, and then directly package, even if it is not online, on your own computer is very good

Project address github.com/spicyShrimp…

Welcome to visit my blog series, just start writing series: iOS development – preface + outline blog.csdn.net/spicyShrimp…