Skip to content

Commit

Permalink
Notes about AppleScript
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Jul 24, 2010
1 parent 0d4098b commit 662ea12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Focus.xcodeproj/felix.mode1v3
Expand Up @@ -276,8 +276,8 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
<integer>12</integer>
<integer>1</integer>
<integer>28</integer>
<integer>27</integer>
<integer>0</integer>
</array>
</array>
Expand Down Expand Up @@ -331,7 +331,7 @@
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>DC71E2A911FB69260028CE6A</string>
<string>DC71E2B611FB6B7C0028CE6A</string>
<key>history</key>
<array>
<string>DCCA269D11FB1F56009E4388</string>
Expand Down Expand Up @@ -546,7 +546,6 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
<string>DC71E2B111FB69260028CE6A</string>
<string>DC71E2B211FB69260028CE6A</string>
<string>DC71E2B311FB69260028CE6A</string>
<string>1C78EAAD065D492600B07095</string>
Expand Down
5 changes: 5 additions & 0 deletions FocusAppDelegate.m
Expand Up @@ -47,6 +47,9 @@ - (void)focus

- (void)captureActiveApp
{
// I know what you think ... why isn't he using some native Cocoa API's? Well it turns out Cocoa is not meant
// for writing apps that control other apps. So as dirty as this looks, afaik it is the "cleanest" way to
// to do the window focus juggling I'm trying to achieve here.
NSAppleScript *as = [[NSAppleScript alloc] initWithSource:@"path to frontmost application as string"];
NSString *path = [[as executeAndReturnError:nil] stringValue];

Expand All @@ -63,6 +66,7 @@ - (void)activateActiveApp
return;
}

// see comment in: captureActiveApp
NSString *script = [NSString stringWithFormat:
@"set front_app to (\"%@\")\ntell application front_app\nactivate\nend tell\n",
activeApp
Expand All @@ -77,6 +81,7 @@ - (void)clear
[backdrop makeKeyAndOrderFront:NSApp];
}

// see comment in: captureActiveApp
NSString *script = [NSString stringWithFormat:
@"set front_app to (\"Focus.app\")\ntell application front_app\nactivate\nend tell\n",
activeApp
Expand Down

0 comments on commit 662ea12

Please sign in to comment.