diff --git a/cmd/app/print.go b/cmd/app/print.go index c0c525c..ba5c6ef 100644 --- a/cmd/app/print.go +++ b/cmd/app/print.go @@ -25,16 +25,31 @@ func getPrintCmd() *cobra.Command { flagSet := pflag.NewFlagSet("print", pflag.ExitOnError) flagSet.StringP("element", "e", "", "element id/value to be filtered") flagSet.Bool("strict", false, "to force id match exactly with the element id/value") + flagSet.StringP("type", "t", "", "type of element. This is OS dependant. For windows it is the type of element (i.e Window) for mac is the bundle id") + flagSet.StringP("title", "", "", "title of the main window") c.Flags().AddFlagSet(flagSet) return c } func print() error { - a, err := app.LoadForefrontApp() + var a *app.App + var err error + aType := viper.GetString("type") + aTitle := viper.GetString("title") + if len(aType) > 0 && len(aTitle) > 0 { + a, err = app.LoadAppByTypeAndTitle( + aType, + aTitle, + ) + } else { + a, err = app.LoadForefrontApp() + } if err != nil { return err } - a.Print(viper.GetString("element"), viper.IsSet("strict")) + a.Print( + viper.GetString("element"), + viper.IsSet("strict")) return nil } diff --git a/pkg/os/darwin/api/appkit/nsrunningapplication.m b/pkg/os/darwin/api/appkit/nsrunningapplication.m index a81b09c..200df31 100644 --- a/pkg/os/darwin/api/appkit/nsrunningapplication.m +++ b/pkg/os/darwin/api/appkit/nsrunningapplication.m @@ -16,13 +16,13 @@ BOOL CheckAccess() { void* FindRunningApplication(const char *bundleID, const char *windowTitle) { @autoreleasepool { NSString *nBundleID = [NSString stringWithUTF8String:bundleID]; - // NSLog(@"Bundle is %@ \n", nBundleID); + NSLog(@"Bundle is %@ \n", nBundleID); NSString *nWindowTitle = [NSString stringWithUTF8String:windowTitle]; - // NSLog(@"WindowTitle is %@ \n", nWindowTitle); + NSLog(@"WindowTitle is %@ \n", nWindowTitle); NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; NSArray* runningApps = [workspace runningApplications]; for (NSRunningApplication* app in runningApps) { - // NSLog(@"app bundle %@ \n", [app bundleIdentifier]); + NSLog(@"app bundle %@ \n", [app bundleIdentifier]); pid_t pid = [app processIdentifier]; AXUIElementRef appRef = AXUIElementCreateApplication(pid); AXError err;