使用Applescript从Mac地址簿中删除地址字段

问题描述:

Facebook同步应用程序将我的Mac地址簿联系人的地址字段填入其城市。拥有大量无用地址的人会让人们难以在Google地图应用中进行搜索(最终会滚动浏览很多人 - 我只想看看那些输入了正确地址的人)。使用Applescript从Mac地址簿中删除地址字段

我想使用applescript清除我的地址簿中的所有家庭地址字段。我写的东西不多,但不能得到它的工作,可能需要从别人一些帮助,谁知道的AppleScript :)

tell application "Address Book" 
repeat with this_person in every person 
     repeat with this_address in every address of this_person 
      if label of this_address is "home" then 
       remove this_address from addresses of this_person 
      end if 
     end repeat 
    end repeat 
end tell 

我试图扣除多个地址/从其他脚本手机的逻辑,但只能找到添加他们,而不是删除他们。

谢谢! :)

你的逻辑是健全的,而且如果你用delete代替remove,那么你可能会工作,但你可以进一步缩小它;所有你真正需要的是以下几个简单的1.5班轮:

tell application "Address Book" to ¬ 
    delete (addresses of people whose label is "home") 

我想通了这一点由Trevor's AppleScript Scripts,在那里他使用delete看“删除了标识的电子邮件”的剧本摆脱特定的电子邮件地址(它似乎是remove用于删除整个地址卡,而不是其中的一部分),并通过一些实验缩小它(这就是我发现AppleScript编程总是继续......)。

+0

谢谢!这并没有给出任何错误,但似乎也没有产生任何变化:(我重新启动AB,我仍然看到的地址。 但我会修补更多基于此,谢谢:) – cemregr 2009-12-28 10:48:31

+0

这是奇怪的 - 它在我的系统上工作(实际上,它工作得很好,我很高兴我首先对地址簿进行备份:))。你正在运行什么版本的OS X?我正在运行10.5.8;也许这是一个不匹配的问题? – 2009-12-28 17:12:31

+1

我想我可能已经在半年后发现了这个问题:您可能需要在'tell'块中放置一个'save addressbook'来强制它提交更改。 – 2010-05-31 06:00:51

/* 

This program will remove the fb://profile links from your 
contact cards. I would suggest creating an addressbook archive 
first before running this against your actual contacts. The easiest 
way to use this is to search your contact cards for "profile" select 
all and export as a single vCard. Then compile and run this program with 
that vCard as input and specify an output file, say fbRemoved.vcf 

I found that AddressBook behaves oddly when I try to do a mass import 
selecting use new for all cards. To get around this I just deleted all 
cards I had selected in the "profile" search then imported fbRemoved.vcf 

Written by: Alexander Millar 
Date: 30 Feb 2010 

*/ 

#include <iostream> 
#include <iomanip> 
#include <stdio.h> 
#include <fstream> 
#include <string> 

using namespace std; 

bool contains_fb_link(string str) { 
    size_t found; 
    found = str.find("fb\\://profile/"); 
    if(found!=string::npos) 
    { 
     return true; 
    } 
    return false; 
} 

int main(int argc, char *argv[]) { 
    istream *infile; 
    ostream *outfile = &cout; 
    string str; 

    switch (argc) { 
    case 3: 
    outfile = new ofstream(argv[2]); 
    if (outfile->fail()) { 
     cerr << "Error! Could not open output file \"" << argv[2] << "\"" << endl; 
     exit(-1); 
    } 
    case 2: 
    infile = new ifstream(argv[1]); 
    if (infile->fail()) { 
     cerr << "Error! Could not open input filee\"" << argv[1] << "\"" << endl; 
     exit(-1); 
    } 
    break; 
    default: 
    cerr << "Usage: " << argv[0] << " input-file [output-file]" << endl; 
    } 

    for (;;) { 
    getline(*infile,str); 
    if(infile->eof()) break ; 

    if(contains_fb_link(str)) 
    { 
     getline(*infile,str); 
     if(infile->eof()) break ; 
    } 
    else 
    { 
     *outfile << str << endl; 
    } 
    } 
} 
+1

欢迎来到StackOverfow!我没有测试你的程序,而是努力+1。另外,没有2月30日。 – Potatoswatter 2010-03-31 06:27:03