-1

I'm trying show hidden files in Finder by running a terminal command. The problem is it looks like defaults write com.apple.finder AppleShowAllFiles TRUE has multiple launch paths. When I run the which command in terminal followed by the command I'm trying to run, it gives me three paths: /usr/bin/defaults, /usr/bin/write, and /usr/bin/TRUE. I can't set all three as launch paths for the command because .launchPath doesn't accept an array.

How can I run this command?

edit: The problem was I wasn't separating the arguments into separate strings. This code works:

@IBAction func showAllFiles(_ sender: NSMenuItem) {
    let task = Process()
    task.launchPath = "/usr/bin/defaults"
    task.arguments = ["write", "com.apple.finder", "AppleShowAllFiles", "TRUE"]
    task.launch()
    task.waitUntilExit()
}
Nate
  • 473
  • 3
  • 14
  • btw, [XtraFinder](https://www.trankynam.com/xtrafinder/) lets you add a button to the finder toolbar which lets you show/hide hidden files – Alexander Jan 26 '17 at 02:19
  • can you add the swift code how you create the task - otherwise it looks not swift related – muescha Jan 26 '17 at 03:46

1 Answers1

0

You're looking for /usr/bin/defaults. The reason you're getting this output is because the following command:

which defaults write com.apple.finder AppleShowAllFiles TRUE

is like doing:

which defaults
which write
which com.apple.finder
which AppleShowAllFiles
which TRUE

which prints:

/usr/bin/defaults

/usr/bin/write

(nothing)

(nothing)

(nothing)

/usr/bin/TRUE

Community
  • 1
  • 1
Alexander
  • 59,041
  • 12
  • 98
  • 151
  • That's good to know. How do I run `defaults write com.apple.finder AppleShowAllFiles TRUE` in Swift then? – Nate Jan 26 '17 at 02:19