+sub get_cocoa_prefs($) {
+ my ($id) = @_;
+ my $v;
+
+ print STDERR "$progname: reading Cocoa prefs: \"$id\"\n" if ($verbose > 1);
+
+ $v = get_cocoa_pref_1 ($id, "textMode");
+ $text_mode = $v if defined ($v);
+
+ # The "textMode" pref is set to a number instead of a string because I
+ # can't figure out the black magic to make Cocoa bindings work right.
+ #
+ if ($text_mode eq '0') { $text_mode = 'date'; }
+ elsif ($text_mode eq '1') { $text_mode = 'literal'; }
+ elsif ($text_mode eq '2') { $text_mode = 'file'; }
+ elsif ($text_mode eq '3') { $text_mode = 'url'; }
+
+ $v = get_cocoa_pref_1 ($id, "textLiteral");
+ $text_literal = $v if defined ($v);
+
+ $v = get_cocoa_pref_1 ($id, "textFile");
+ $text_file = $v if defined ($v);
+
+ $v = get_cocoa_pref_1 ($id, "textProgram");
+ $text_program = $v if defined ($v);
+
+ $v = get_cocoa_pref_1 ($id, "textURL");
+ $text_url = $v if defined ($v);
+}
+
+
+sub get_cocoa_pref_1($$) {
+ my ($id, $key) = @_;
+ # make sure there's nothing stupid/malicious in either string.
+ $id =~ s/[^-a-z\d. ]/_/gsi;
+ $key =~ s/[^-a-z\d. ]/_/gsi;
+ my $cmd = "defaults -currentHost read \"$id\" \"$key\"";
+
+ print STDERR "$progname: executing $cmd\n"
+ if ($verbose > 3);
+
+ my $val = `$cmd 2>/dev/null`;
+ $val =~ s/^\s+//s;
+ $val =~ s/\s+$//s;
+
+ print STDERR "$progname: Cocoa: $id $key = \"$val\"\n"
+ if ($verbose > 2);
+
+ $val = undef if ($val =~ m/^$/s);
+
+ return $val;
+}
+
+