sinter icon indicating copy to clipboard operation
sinter copied to clipboard

[Feature request] execute (shell) script when specified apps/processes launch

Open JayBrown opened this issue 5 years ago • 1 comments

It would be great to somehow configure sinter to execute shell scripts when apps with specified bundle IDs launch (or processes from a certain path): sinter would halt the app/process launch, pass process information to the script (bundle ID, process ID, execution path etc.), and wait for the script to finish, before applying any rules. Possible?

JayBrown avatar Aug 21 '20 15:08 JayBrown

Something like this, which I'm currently using in my own solution, that I cobbled together (getting info from NSDistributedNotifications, which however only works for actual applications, not CLIs, not even most menu bar apps):

-(void) launchedApp: (NSNotification*) notification {
  NSDictionary *userInfo = [notification userInfo]; // read full application launch info
  NSString* AppPID = [userInfo objectForKey:@"NSApplicationProcessIdentifier"]; // parse for AppPID
  int killPID = [AppPID intValue]; // define integer from NSString
  kill((killPID), SIGSTOP); // interrupt app launch
  NSString* AppPath = [userInfo objectForKey:@"NSApplicationPath"]; // read application path
  NSString* AppBundleID = [userInfo objectForKey:@"NSApplicationBundleIdentifier"]; // read BundleID
  NSString* AppName = [userInfo objectForKey:@"NSApplicationName"]; // read AppName
  NSLog(@":::%@:::%@:::%@:::%@", AppPID, AppPath, AppBundleID, AppName); // output to stderr
}

JayBrown avatar Aug 27 '20 16:08 JayBrown