例如:显示当前的任务名称和剩余时间
借鉴了评论大牛的推荐,最终没有达到期望,在github发现了使用objc和Appscript交互的想法,通过脚本调用emacsclient -e '(org-clock-get-clock-string)'
方法,获取emacs中定时器的信息,让后使用objc新建NSStatusBar显示即可:
#pragma mark - emacs
-(NSString *)emacsTaskName
{
NSString *active = [self outOfAppScriptcommand:@"org-clock-is-active"];
if ([active isEqualToString:@"nil"]) {
return @"无安排";
}
NSString *clock = [self outOfAppScriptcommand:@"org-clock-get-clock-string"];
//处理字符串:#(" [22:54] (org-agenda 科学使用 [0%])" 0 31
//(face org-mode-line-clock))
clock = [RX(@"\\[\\d.*\\)") firstMatch:clock];
return clock;
}
//通过AppScript脚本获取任务
-(NSString *)outOfAppScriptcommand:(NSString *)command
{
NSString *script = [NSString stringWithFormat:@"on run\ndo shell script \"/usr/local/bin/emacsclient -e '(%@)'\"\nend run",command];
NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:script];
NSString *result = @"nil";
NSDictionary* errorDict;
NSAppleEventDescriptor* returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
if (!errorDict)
{
result = returnDescriptor.stringValue;
}
return result;
}
项目见: