連絡先appから書き出した.vcfカードを同じ連絡先appに読み込んだ時、カード内容が反映せず”名前なし”となる

macOS 26.4 Tahoeの連絡先appバージョン14.0 (2732.500.131.1.1)における事象です。


手順)

1.連絡先appで特定の連絡先を選択し「ファイル>書き出す>vCardを書き出す...」で.vcfカードに出力する。

出力したデータ(個人情報はマスクしてありますが正しい内容が書き出されている

  

2.当該.vcfファイルをQuickLookで表示した場合も内容は表示されない。

 (住所の先頭になる郵便番号だけが表示される)

  

3.該当連絡先を削除したのち、書き出した.vcfファイルを連絡先appに読み込ませたところ

 郵便番号以外のデータが全く読み込まれず”名前なし”となってしまう。


この事象について、何かご存知の方はお知らせください。



※ 今まで連絡先のバックアップとしてvCardへの書き出し保存で対応していましたが、そのデータから復元できないのでは話になりません。



MacBook Air 13″, macOS 26.4

投稿日 2026/04/04 22:56

返信
スレッドに付いたマーク ランキングトップの返信

投稿日 2026/04/05 02:02

うまく動作するロジックを見つけました。

How Do I Export vCards from Apple Contacts using AppleScript? - Questions & Suggestions - Keyboard Maestro Discourse

これです。

	set HomePath to (path to home folder) as text
	set FolderPath to "temp:"
	set FolderPath1 to HomePath & FolderPath as text
	do shell script "mkdir -p " & POSIX path of FolderPath1
	
	alias FolderPath1
	tell application "Contacts"
		set {contactNames, vCards} to {name, vcard} of people
		quit
	end tell
	set treatedNames to {}
	repeat with i from 1 to (count contactNames)
		set bareName to (item i of contactNames)
		if bareName is in treatedNames then
			set nameOfvCard to bareName & "_" & i & ".vcf"
		else
			set end of treatedNames to bareName
			set nameOfvCard to bareName & ".vcf"
		end if
		set outFile to (open for access file (FolderPath1 & nameOfvCard) with write permission)
		try
			set eof outFile to 0
			write (item i of vCards) to outFile as «class utf8»
		end try
		close access outFile
	end repeat
	


ポイントは、

  1. vCardを配列として連絡先appから取り出す。
  2. tell application "Contacts"の外でその配列をファイルに書き出す。

これでうまくutf8で書き出してくれるようになりました。


もっといい方法があればお教えください。

よろしくお願いします。

返信: 20
スレッドに付いたマーク ランキングトップの返信

2026/04/05 02:02 Pajerow への返信

うまく動作するロジックを見つけました。

How Do I Export vCards from Apple Contacts using AppleScript? - Questions & Suggestions - Keyboard Maestro Discourse

これです。

	set HomePath to (path to home folder) as text
	set FolderPath to "temp:"
	set FolderPath1 to HomePath & FolderPath as text
	do shell script "mkdir -p " & POSIX path of FolderPath1
	
	alias FolderPath1
	tell application "Contacts"
		set {contactNames, vCards} to {name, vcard} of people
		quit
	end tell
	set treatedNames to {}
	repeat with i from 1 to (count contactNames)
		set bareName to (item i of contactNames)
		if bareName is in treatedNames then
			set nameOfvCard to bareName & "_" & i & ".vcf"
		else
			set end of treatedNames to bareName
			set nameOfvCard to bareName & ".vcf"
		end if
		set outFile to (open for access file (FolderPath1 & nameOfvCard) with write permission)
		try
			set eof outFile to 0
			write (item i of vCards) to outFile as «class utf8»
		end try
		close access outFile
	end repeat
	


ポイントは、

  1. vCardを配列として連絡先appから取り出す。
  2. tell application "Contacts"の外でその配列をファイルに書き出す。

これでうまくutf8で書き出してくれるようになりました。


もっといい方法があればお教えください。

よろしくお願いします。

2026/04/05 05:03 Pajerow への返信

こんな感じでできませんか?


set HomePath to (path to home folder) as text
set FolderPath to "temp:"
set FolderPath1 to HomePath & FolderPath as text
do shell script "mkdir -p " & quoted form of POSIX path of FolderPath1

alias FolderPath1
tell application "Contacts"
    activate
    repeat with cardPerson in people
        set nameOfvCard to name of cardPerson & ".vcf"
        set fp to open for access file (FolderPath1 & nameOfvCard) with write permission
        write (vcard of cardPerson as text) to fp as «class utf8»
        close access fp
    end repeat
    quit
end tell


2026/04/06 04:33 Pajerow への返信

ええと、説明が下手ですみません。前掲のドキュメントには次のように書いてあります。



ざっくり言うと、write コマンドは as パラメータなし、または as text あるいは as string の場合は primary encoding、as Unicode text は UTF-16 を使うことになってます。


で、ここで言う primary encoding は UTF-8 ではなく、OS の言語設定に応じたエンコーディングと思われます。(日本語環境の場合は MacJapanese、英語環境だと MacRoman)


なので、日本語環境下で as パラメータなしでファイルに書き込んだら MacJapanese になった、、、というのは仕様どおりなのだろうと。


また、英語環境下で as パラメータなしでファイルに書き込むと MacRoman になりますし、as Unicode text だと UTF-16、記載はありませんが as «class utf8» は UTF-8 になるのでバグではないと思います。


ただ、デフォルトのエンコーディングは UTF-8 であってほしいというのが多くの人の望むところでしょうから、仕様変更の要望はありかなと。


2026/04/05 13:03 Hiro__S への返信

Hiro__Sさん、おはようございます。


お教えいただいたスクリプトでうまくいきました!


違いはここだけ?

ダメなもの)

set outFile to (open for access file (FolderPath1 & nameOfvCard) with write permission)


OKのもの)

set fp to open for access file (FolderPath1 & nameOfvCard) with write permission


"( )"の有無だけでこんなに大きな違いがでるのですね。 このカッコは必要ないものなのでしょうか? 文法が理解できていないのでなぜなのかは分かりません。

”ダメな”スクリプトもネット上から探してきたものなのですが、全角文字のない英語圏などでは問題にはならないのでしょう。



おかげさまで問題点は発見できました。

ありがとうございました。


ただ、このロジックと前述した別のロジック(配列に読み込む方法)では処理速度が全然異なり後者の方が断然速かったです。

2026/04/05 00:50 はに への返信

はにさん、こんにちは。


連絡先appメニューから書き出し、読み込みをすると問題は発生しないのですね。

当方でもこれを確認できました。


実は、私は連絡先バックアップを下記のAppleScriptで行っています。

	set HomePath to (path to home folder) as text
	set FolderPath to "temp:"
	set FolderPath1 to HomePath & FolderPath as text
	do shell script "mkdir -p " & POSIX path of FolderPath1
	
	alias FolderPath1
	tell application "Contacts"
		activate
		repeat with cardPerson in people
			set nameOfvCard to name of cardPerson & ".vcf"
			set outFile to (open for access file (FolderPath1 & nameOfvCard) with write permission)
			write (vcard of cardPerson as text) to outFile
			close access outFile
		end repeat
		quit
	end tell
	


で、このScriptで書き出すと、”日本語の文字コードがShift-JISになる”ことがわかりました。

連絡先appのメニューから書き出した時はutf8になるようなのでこの違いが原因のようです。


Scriptのwtite命令に”as «class utf8»"を追加してみましたがうまくいきませんでした。

どう記述すればいいのでしょうか?


2026/04/05 15:59 Pajerow への返信

すいません。わたしの勘違いがありました。


うまくいかなかった原因は

write (vcard of cardPerson as text) to outFile

write (vcard of cardPerson as text) to fp as «class utf8»

の違い、つまり

as «class utf8»

の有無でした。


事前に一度試した時はうまくいかなかった気がしたんですが、確認方法が間違っていたようです。

2026/04/06 04:47 Hiro__S への返信

ここにも同様のことが書かれてますね。

Commands Reference


as class

Write the data as this class. The most common ones control the use of three different text encodings:

text or string

The primary text encoding, as determined by the user’s language preferences set in the International preference panel. (For example, Mac OS Roman for English, MacJapanese for Japanese, and so on.)

Unicode text

UTF-16.

«class utf8»

UTF-8.

Any other class is possible, for example date or list, but is typically only useful if the data will be read using a read statement specifying the same value for the as parameter.

Default Value:

The class of the supplied data. See Special Considerations.



で、as classを書かなければMacjapanese(SHIFT-JIS+α)になると理解していいのでしょうか?

MacJapanese - Wikipedia

2026/04/05 21:09 Pajerow への返信

ちょっと前からAppleスクリプトはUTF 8で統一されるようになったと聞いてます。もしデフォルトでSJISになってしまうようなら、それはバグじゃないのですか?

実際、今回の例でもファイル名はUTF 8になってます。

フィ-ドバックしておく方が良いのでは?

2026/04/05 19:52 Hiro__S への返信

>こんな感じにしちゃったのかなと想像しました。

ではなかったのですが、

出力ファイルが何種類かあって実行したスクリプトとの対応付が違っていたのだと思います。


>あとはエラー対策として2つ目のコードのように try 文を使えば尚よしです。

はい、今は2つ目のコードで実行するようにしました。



Hiro__SさんにはAppleScriptに関して色々とお教えいただき感謝です。

いつのまにか還暦よりも古希が近くなりプログラミングに関して頭が回らずだいぶんしんどくなりました。(^^)

2026/04/05 19:53 Pajerow への返信

本題から若干逸れますが、、、コードの変更箇所を確認するには Xcode の中に入ってる FileMerge.app がおすすめです。


FileMerge.app の在処

/Applications/Xcode.app/Contents/Applications/FileMerge.app


設定


Estension
scpt


Filter
/usr/bin/osadecompile $(FILE)


で、結果はこんな感じになります。


2026/04/05 23:45 はに への返信

>ちょっと前からAppleスクリプトはUTF 8で統一されるようになったと聞いてます。

>もしデフォルトでSJISになってしまうようなら、それはバグじゃないのですか?

そうなんですか?

ずいぶん古いですがこんな記事もあったので...

AppleScript/write text to file.applescript at master · veadar/AppleScript · GitHub


昔の仕様のまま放置されているのでしょうかね。

フィードバックしときます。

2026/04/06 00:13 Pajerow への返信

AppleScript は Mac OS X 10.5 Leopard で Unicode ベースとなりました。


10.5 Changes


ところが、ファイルへの書き込みについては癖が強い仕様なんです。今回の件についても UTF-8 を指定 (as «class utf8») すれば UTF-8で書き込まれることからバグとは言えないような...


AppleScript ではシェルスクリプトのリダイレクションが使えますし、最近の OS では Objective-C のメソッドも使えるようになりました。ファイルへの書き込みはこちらの方が圧倒的に使い勝手が良いです。

2026/04/06 07:41 Hiro__S への返信

生成されるファイル名について今気づいたことがあるので追加しておきますね。


open for access ... で生成するファイル名には Unicode 正規化処理が施されるようで、例えば「」のファイル名は「.vcf」になります。


一方、Contacts.app の「メニューバー > ファイル > 書き出す」は正規化しないようです。


なので、ファイル名が異なる場合があります。肝心のデータは正規化されないので問題ないと思いますが、一応、、、ご参考まで。


いろいろ勉強になりました。ありがとうございます。

# 細かく調査すると沼にはまりそうなのでもうやめときます。


2026/04/05 19:30 Pajerow への返信

うまくいきました!


あとはエラー対策として2つ目のコードのように try 文を使えば尚よしです。


事前に一度試した時はうまくいかなかった気がしたんですが


こんな感じにしちゃったのかなと想像しました。

write (vcard of cardPerson as «class utf8») to outFile


連絡先appから書き出した.vcfカードを同じ連絡先appに読み込んだ時、カード内容が反映せず”名前なし”となる

Apple サポートコミュニティへようこそ
Apple ユーザ同士でお使いの製品について助け合うフォーラムです。Apple Account を使ってご参加ください。