Ensure the owner of launch agents dir is current user.
This commit is contained in:
@ -50,12 +50,36 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
var statusItem: NSStatusItem!
|
||||
static let StatusItemIconWidth: CGFloat = NSVariableStatusItemLength
|
||||
|
||||
func ensureLaunchAgentsDirOwner () {
|
||||
let dirPath = NSHomeDirectory() + "/Library/LaunchAgents"
|
||||
let fileMgr = FileManager.default
|
||||
if fileMgr.fileExists(atPath: dirPath) {
|
||||
do {
|
||||
let attrs = try fileMgr.attributesOfItem(atPath: dirPath)
|
||||
if attrs[FileAttributeKey.ownerAccountName] as! String != NSUserName() {
|
||||
//try fileMgr.setAttributes([FileAttributeKey.ownerAccountName: NSUserName()], ofItemAtPath: dirPath)
|
||||
let bashFilePath = Bundle.main.path(forResource: "fix_dir_owner.sh", ofType: nil)!
|
||||
let script = "do shell script \"bash \(bashFilePath) \(NSUserName()) \" with administrator privileges"
|
||||
if let appleScript = NSAppleScript(source: script) {
|
||||
var err: NSDictionary? = nil
|
||||
appleScript.executeAndReturnError(&err)
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
NSLog("Error when ensure the owner of $HOME/Library/LaunchAgents, \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
|
||||
_ = LaunchAtLoginController()// Ensure set when launch
|
||||
|
||||
NSUserNotificationCenter.default.delegate = self
|
||||
|
||||
self.ensureLaunchAgentsDirOwner()
|
||||
|
||||
// Prepare ss-local
|
||||
InstallSSLocal()
|
||||
InstallKcptunClient()
|
||||
|
12
ShadowsocksX-NG/fix_dir_owner.sh
Executable file
12
ShadowsocksX-NG/fix_dir_owner.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
# fix_dir_owner.sh
|
||||
# ShadowsocksX-NG
|
||||
#
|
||||
# Created by 邱宇舟 on 2017/8/25.
|
||||
# Copyright © 2017年 qiuyuzhou. All rights reserved.
|
||||
|
||||
|
||||
LAUNCH_AGENTS_DIR="$HOME/Library/LaunchAgents"
|
||||
sudo chown $@ "$HOME/Library/LaunchAgents"
|
||||
|
Reference in New Issue
Block a user