Last active
December 15, 2015 23:39
-
-
Save TomLiu/5342242 to your computer and use it in GitHub Desktop.
Get Finder Current Path & Current Selection using AppleScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AppDelegate.h" | |
@implementation AppDelegate | |
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification | |
{ | |
NSDictionary *error = nil; | |
NSString *source = @"tell application \"Finder\"\ntry\nset dir to the target of the front window\nreturn POSIX path of (dir as text)\non error\nreturn \"/\"\nend try\nend tell"; | |
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:source]; | |
NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&error]; | |
NSLog(@"%@", descriptor.stringValue); | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AppDelegate.h" | |
@implementation AppDelegate | |
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification | |
{ | |
NSDictionary *error = nil; | |
NSString *source = @"tell application \"Finder\"\nset selectedItem to (POSIX path of (the selection as alias))\nreturn selectedItem\nend tell"; | |
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:source]; | |
NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&error]; | |
NSLog(@"%@", descriptor.stringValue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment