2014-01-14 26 views
0

我想了解使用XCode 5爲OSX Automator創建的操作。如何將AppleScript變量的內容傳輸到Objective-C操作

所以我用的模板 「的Automator動作」 是這樣的:

- (id)runWithInput:(id)input fromAction:(AMAction *)anAction error:(NSDictionary **)errorInfo 
{ 
    // we expect to receive "Hello World" in the input variable 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES); 
    NSString *desktopDirectory = [paths objectAtIndex:0]; // Get desktop directory 
    NSString *logStr = @""; 

    logStr = [ NSString stringWithFormat:@"founded %lu", (unsigned long)[input count]]; 
    [ logStr writeToFile:[ desktopDirectory stringByAppendingPathComponent:@"log.txt" ] atomically:YES encoding:NSUTF8StringEncoding error:nil ]; 

    return input;   
} 

在Automator中,我創建了2個步驟:

第一:一個AppleScript動作,做這個:

on run {input, parameters} 
    return "Hello World" 
end run 

正如你可以看到它只是返回文本「Hello World」

二,我的我使用Xcode創建的操作。

但是,當我運行工作流程......沒有錯誤,但輸入參數(這是一個NSArray)不包含任何內容!

你知道如何將AppleScript變量的內容傳遞給Objective-C動作嗎?

謝謝你的幫助。

回答

2

我找到了!

下的「由Automator的行動接受輸入型」項目設置我的com.apple.cocoa.string

更換com.apple.cocoa.path還有我得到很好的價值。

相關問題