Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions cmd/app/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions pkg/os/darwin/api/appkit/nsrunningapplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down