Skip to content

Commit

Permalink
Add iconset processing to icns
Browse files Browse the repository at this point in the history
  • Loading branch information
gillesdubois committed Oct 9, 2017
1 parent a4cbe7d commit 3f81515
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions ImageToIcns/ImageToIcnsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import Cocoa

class ImageToIcnsViewController: NSViewController {

var destFolder: URL?
var sourcePath: String?
var destFolder: URL!
var sourcePath: String!
var fileName: String! = "output_file"

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -39,14 +40,45 @@ class ImageToIcnsViewController: NSViewController {
self.destFolder = panel.urls[0]

// Process image
print ("Destination folder : \(self.destFolder?.path ?? "none")")
print ("Source folder : \(self.sourcePath ?? "none")")

// Transform source to icns
let task = Process()

// Create a Task instance

let output = "\(self.destFolder!.path)/\(self.fileName!).icns"

print ("Destination folder : \(output)")

// Set the task parameters
task.launchPath = "/usr/bin/iconutil"
task.arguments = ["-c", "icns", "\(self.sourcePath!)", "--output", "\(output)"]

// Create a Pipe and make the task
// put all the output there
let pipe = Pipe()
task.standardOutput = pipe

// Launch the task
task.launch()

// Trigger notification
self.showNotification()


}
}

}

private func showNotification() -> Void {
let notification = NSUserNotification()
notification.title = "Success !"
notification.informativeText = "Your iconset has been transformed to icns"
notification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.deliver(notification)
}

}

0 comments on commit 3f81515

Please sign in to comment.