Skip to content

Commit ce87f76

Browse files
committed
• Changed a symbol name, comments.
1 parent 011032e commit ce87f76

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

Diff for: SSYLaunchdGuy.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ extern NSString* const SSYLaunchdGuyErrorKeyNSTaskError ;
55
extern NSString* const SSYLaunchdGuyErrorKeyCommandStderr ;
66

77
/*!
8-
@brief A class for manipulating launchd agents. All methods in this
9-
class manipulate only launchd agents in the current user's Mac account.
8+
@brief A class for manipulating launchd agents in the current Macintosh
9+
user account.
10+
11+
@details This class is a wrapper around what Apple now calls "legacy"
12+
commands of the launchctl command-line program. See man launchctl(1). I
13+
don't know why these commands are "legacy". They are not "deprecated".
14+
They still work fine for me (macOS 10.12.5). However, I would not use this
15+
code for new designs without further research.
1016
1117
@details Agent names will be of the form:
1218
identifier.agentIndex

Diff for: SSYLaunchdGuy.m

+16-17
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ + (BOOL)removeAgentWithLabel:(NSString*)label
607607
NSString* directory = [SSYLaunchdBasics homeLaunchAgentsPath] ;
608608
NSString* plistPath = [directory stringByAppendingPathComponent:filename] ;
609609

610-
// Added in BookMacster 1.5.7:
611610
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
612611
return YES ;
613612
}
@@ -617,7 +616,7 @@ + (BOOL)removeAgentWithLabel:(NSString*)label
617616
BOOL isLoaded = [self isLoadedLabel:label] ;
618617

619618

620-
NSString* cmdPath = [[NSFileManager defaultManager] temporaryFilePath] ;
619+
NSString* scriptPath = [[NSFileManager defaultManager] temporaryFilePath] ;
621620
// I presumed we need execute permissions, which we don't get from
622621
// -[NSString writeToFile::], so I do it this way:
623622
NSNumber* octal755 = [NSNumber numberWithUnsignedLong:0755] ;
@@ -629,15 +628,15 @@ + (BOOL)removeAgentWithLabel:(NSString*)label
629628
octal755, NSFilePosixPermissions,
630629
nil] ;
631630

632-
// Generate the command (cmd) as a multi-line string
631+
// Generate the shell script as a multi-line string
633632
NSMutableString* formatString = [[NSMutableString alloc] init] ;
634633
[formatString appendString:
635634
@"#!/bin/sh\n" // shebang
636635
@"PLIST_PATH=\"%@\"\n" // define environment variable
637636
@"sleep %d\n" ] ; // for optional delaySeconds
638637
if (isLoaded) {
639638
[formatString appendString:
640-
@"/bin/launchctl unload -wF \"$PLIST_PATH\"\n"] ; // Unload the agent
639+
@"/bin/launchctl unload -wF \"$PLIST_PATH\"\n"] ;// Unload the agent
641640
}
642641
if (justReload) {
643642
[formatString appendString:
@@ -646,26 +645,26 @@ + (BOOL)removeAgentWithLabel:(NSString*)label
646645
}
647646
else {
648647
[formatString appendString:
649-
@"rm \"$PLIST_PATH\"\n" ] ; // Remove the plist file
648+
@"/bin/rm -f \"$PLIST_PATH\"\n" ] ; // Remove the plist file, if still present. It might be gone if a previous run of this method was in process and had not deleted it before this method was invoked again.
650649
}
651650
[formatString appendString:
652-
@"rm \"%@\"\n"] ; // Remove this script's file (self-destruct)
653-
NSString* cmd = [NSString stringWithFormat:
654-
formatString,
655-
plistPath,
656-
delaySeconds,
657-
cmdPath] ;
651+
@"/bin/rm \"%@\"\n"] ; // Remove this script's file (self-destruct)
652+
NSString* script = [NSString stringWithFormat:
653+
formatString,
654+
plistPath,
655+
delaySeconds,
656+
scriptPath] ;
658657
[formatString release] ;
659658

660-
// Write the command to a file
661-
NSData* data = [cmd dataUsingEncoding:NSUTF8StringEncoding] ;
662-
[[NSFileManager defaultManager] createFileAtPath:cmdPath
659+
// Write the script to a file
660+
NSData* data = [script dataUsingEncoding:NSUTF8StringEncoding] ;
661+
[[NSFileManager defaultManager] createFileAtPath:scriptPath
663662
contents:data
664663
attributes:attributes] ;
665664

666-
// Run that file
665+
// Run that script file
667666
NSTask* task = [[NSTask alloc] init] ;
668-
[task setLaunchPath:cmdPath] ;
667+
[task setLaunchPath:scriptPath] ;
669668
[task launch] ;
670669
[task release] ;
671670

@@ -676,7 +675,7 @@ + (BOOL)removeAgentWithLabel:(NSString*)label
676675
if (timeout > 0.0) {
677676
SSYPathWaiter* waiter = [[SSYPathWaiter alloc] init] ;
678677
ok = [waiter blockUntilWatchFlags:SSYPathObserverChangeFlagsDelete
679-
path:cmdPath
678+
path:scriptPath
680679
timeout:timeout] ;
681680
[waiter release] ;
682681
}

0 commit comments

Comments
 (0)