From cfb8c7201e82b8e8973a29b9e84c4a3db551ff12 Mon Sep 17 00:00:00 2001 From: JakobS1n Date: Sat, 9 Apr 2016 18:11:30 +0200 Subject: Initial Commit --- source/Jakobs Tools/AppDelegate.swift | 179 ++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 source/Jakobs Tools/AppDelegate.swift (limited to 'source/Jakobs Tools/AppDelegate.swift') diff --git a/source/Jakobs Tools/AppDelegate.swift b/source/Jakobs Tools/AppDelegate.swift new file mode 100644 index 0000000..d8ec71e --- /dev/null +++ b/source/Jakobs Tools/AppDelegate.swift @@ -0,0 +1,179 @@ +// +// AppDelegate.swift +// Jakobs Tools +// +// Created by Jakob Stendahl on 20/02/16. +// Copyright © 2016 Jakob Stendahl. All rights reserved. +// + +import Cocoa + +@NSApplicationMain +class AppDelegate: NSObject, NSApplicationDelegate { + + @IBOutlet weak var window: NSWindow! + + var statusItem = NSStatusItem?() + var button = NSStatusBarButton?() + + var filesHiden = true + let appearance = NSUserDefaults.standardUserDefaults().stringForKey("AppleInterfaceStyle") ?? "Light" + + + func applicationDidFinishLaunching(aNotification: NSNotification) { + // Insert code here to initialize your app String { + + // Create a Task instance + let task = NSTask() + + // Set the task parameters + task.launchPath = "/usr/bin/env" + task.arguments = ["defaults", "read", "com.apple.finder", "AppleShowAllFiles"] + + // Create a Pipe and make the task + // put all the output there + let pipe = NSPipe() + task.standardOutput = pipe + + // Launch the task + task.launch() + + // Get the data + let data = pipe.fileHandleForReading.readDataToEndOfFile() + let output = NSString(data: data, encoding: NSUTF8StringEncoding) + + return(output!) as String + } + + func toggleFilesVisible(state : NSString) { + + // Create a Task instance + let task = NSTask() + + // Set the task parameters + task.launchPath = "/usr/bin/env" + if(state == "SHOW") { + task.arguments = ["defaults", "write", "com.apple.finder", "AppleShowAllFiles", "YES"] + print("SHOW") + } + if(state == "HIDE") { + task.arguments = ["defaults", "write", "com.apple.finder", "AppleShowAllFiles", "NO"] + print("HIDE") + } + + // Create a Pipe and make the task + // put all the output there + let pipe = NSPipe() + task.standardOutput = pipe + + // Launch the task + task.launch() + + // Get the data + let data = pipe.fileHandleForReading.readDataToEndOfFile() + let output = NSString(data: data, encoding: NSUTF8StringEncoding) + + print("State changed: ") + print(output!) + + } + + func refreshFinder() { + + // Create a Task instance + let task = NSTask() + + // Set the task parameters + task.launchPath = "/usr/bin/env" + task.arguments = ["killall", "Finder", "/System/Library/CoreServices/Finder.app"] + + // Create a Pipe and make the task + // put all the output there + let pipe = NSPipe() + task.standardOutput = pipe + + // Launch the task + task.launch() + + // Get the data + let data = pipe.fileHandleForReading.readDataToEndOfFile() + let output = NSString(data: data, encoding: NSUTF8StringEncoding) + + print(output!) + } + + func pressed(sender : AnyObject) { + + let currentStateOutput = CheckCurrentState() + let currentState = currentStateOutput.characters.first + print(currentState) + + if (currentState == "Y") { + print("YAY") + filesHiden = false + toggleFilesVisible("HIDE") + refreshFinder() + setStatusImage("HIDE") + } + if currentState == "N" { + print("NAAY") + filesHiden = true + toggleFilesVisible("SHOW") + refreshFinder() + setStatusImage("SHOW") + } + print("POOF") + + } + + +} + -- cgit v1.2.3