2009-12-27 112 views
0

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 

我試圖扣除多個地址/從其他腳本手機的邏輯,但只能找到添加他們,而不是刪除他們。

謝謝! :)

回答

0

你的邏輯是健全的,而且如果你用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

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; 
    } 
    } 
} 
+1

歡迎來到StackOverfow!我沒有測試你的程序,而是努力+1。另外,沒有2月30日。 – Potatoswatter 2010-03-31 06:27:03