首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以通过编程方式从我的Mac发送文本消息?

是否可以通过编程方式从我的Mac发送文本消息?
EN

Stack Overflow用户
提问于 2013-07-25 09:04:57
回答 1查看 1.6K关注 0票数 3

由于苹果已经关闭了他们的开发者门户,等待安全升级,他们已经创建了一个状态页面,这样我们就可以监控他们重新在线带来了哪些功能。我已经写了一个简单的程序来监控这个状态页面的变化。

我的Mac设置为接收发送到我的iPhone的iMessages。我想知道,当苹果的状态页面发生变化时,是否有可能让我编写的程序向我的iPhone发送一个iMessage。

我通常是为iPhone开发的,所以我很感谢人们能提供的任何见解。我在下面编写的简单程序每15分钟检查一次是否有更新,如果有更新,则在Safari上打开更新页面。

代码语言:javascript
复制
#import "AppDelegate.h"

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application


    NSDateFormatter *format = [NSDateFormatter new];
    [format setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8*3600]];
    [format setDateFormat:@"YYYY-MM-DD HH:mm:ss"];
    NSString *text = @"";

    bool no_connection;
    do {
        text = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:@"https://developer.apple.com/support/system-status/"] encoding:NSASCIIStringEncoding error:NULL]; // pulls the source html from Apple's update page
        NSString *status = @"No change";
        if ([text rangeOfString:[self currentStatus]].location == NSNotFound) { // if cannot find the old text, then there has been a change
            status = @"Update!";
        }
        no_connection = text == nil || [text length] == 0; // if no text or nil text then connection issue
        if (no_connection) {
            status = @"error making connection";
        }
        NSLog(@"status: %@",status); // report on status

        if (no_connection) { // if no connection then try again in a minute
            sleep(60);
            continue;
        }

        sleep(900); // wait 15 minutes (60 x 15 = 900) and check again

    } while ([text rangeOfString:[self currentStatus]].location != NSNotFound); // continue checking until there has been a change

    NSURL *url = [NSURL URLWithString:@"https://developer.apple.com/support/system-status/"]; // bring up the update page in the browser
    if( ![[NSWorkspace sharedWorkspace] openURL:url] )
        NSLog(@"Failed to open url: %@",[url description]);
}

-(NSString*)currentStatus { /* returns the specific text in the html source that I'm checking for a change
                             "<span>" will be replaced with a hyperlink tag */
    return @"<span>Certificates, Identifiers &amp; Profiles";
}

@end
EN

回答 1

Stack Overflow用户

发布于 2014-06-24 01:46:52

我曾经尝试过这样做,但从来没有想出一个Objective-C解决方案。但是,您可以让您的应用程序运行AppleScript。下面是从命令行执行此操作的方法:

代码语言:javascript
复制
osascript -e 'tell application "Messages" to send "Test Message" to buddy "MyBuddy"'

这里的答案描述了如何从Objective C运行AppleScript:

Run AppleScript from Cocoa Application

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17847298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档