0

Facebook Sync 应用程序在我的 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

我试图从其他脚本中推断出多个地址/电话的逻辑,但只能找到添加它们,而不是删除它们。

谢谢!:)

4

2 回答 2

1
/*

 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;
    }
  }
}
于 2010-03-31T06:09:44.830 回答
0

你的逻辑是合理的,如果你用 替换它可能会起作用removedelete但你可以进一步缩小它;您真正需要的只是以下简单的 1.5-liner:

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

我通过查看Trevor 的 AppleScript Scripts中的“Remove Emails for Label”脚本发现了这一点,他用它delete来删除特定的电子邮件地址(似乎remove是用于删除整个地址卡,而不是其中的一部分),然后缩小它通过一些实验(这就是我发现 AppleScript 编程总是进行的方式……)。

于 2009-12-27T14:10:53.043 回答