Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/mrgnw/scripts.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738import Foundation
let executableName = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : ".thing"let directoryPath = FileManager.default.currentDirectoryPathlet directoryName = URL(fileURLWithPath: directoryPath).lastPathComponent
let plistFilename = "com.user.thingLauncher.\(directoryName).plist"let plistPath = NSString(string: "~/Library/LaunchAgents/\(plistFilename)").expandingTildeInPath
let plistDict: [String: Any] = [ "Label": "com.user.thingLauncher.\(directoryName)", "ProgramArguments": ["\(directoryPath)/\(executableName)"], "RunAtLoad": true]
// Serialize the dictionary into plist datado { let plistData = try PropertyListSerialization.data(fromPropertyList: plistDict, format: .xml, options: 0) try plistData.write(to: URL(fileURLWithPath: plistPath)) print("LaunchAgent plist created at \(plistPath)")} catch { print("Error creating LaunchAgent plist: \(error)") exit(1)}
// Load the LaunchAgentlet process = Process()process.launchPath = "/bin/launchctl"process.arguments = ["load", plistPath]
do { try process.run() print("LaunchAgent loaded successfully.")} catch { print("Error loading LaunchAgent: \(error)") exit(1)}