Menu

Skip to content
AppleScriptの穴
  • Home
  • Products
  • Books
  • Docs
  • Events
  • Forum
  • About This Blog
  • License
  • 仕事依頼

AppleScriptの穴

Useful & Practical AppleScript archive. Click '★Click Here to Open This Script' Link to download each AppleScript

住所ジオコーダー2026年最新版

Posted on 3月 16 by Takaaki Naganoya

AppleScriptから住所ジオコーダー/逆住所ジオコーダーの機能にアクセスして日常的に利用していますが、セキュリティ機能の強化によって旧来の機能にアクセスできなくなりつつあります。

住所ジオコーダー系の機能については、さまざまな方法でアクセスできるようにしてきましたが、どうやらmacOS 27あたりでさらにセキュリティ縛りがきつくなることが想定されます。

さまざまな方法を検討した結果、

・SwiftでCLIツールを作ってAppleScriptバンドル内に入れてdo shell scriptコマンドで呼び出す

これは実際にNFCタグの操作Scriptを作った際に試した方法です。問題はないのですが、これだと実行できないAppleScriptの実行環境もあるので、なるべく1つのAppleScript内で完結したいところです。

・AppleScript内に文字列でSwiftのプログラムを記述し、do shell scriptコマンド経由で「swift」(/usr/bin/swift)を呼び出して実行させる

今回はこれを採用してみました。AppleScript実行プログラム側のセキュリティ設定次第ですが、環境を選ばずに実行できるはずです。なお、Script Debugger上では動作しません。

AppleScript名:住所から緯度、経度を返す(Swift版).scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2026/03/16
—
–  Copyright © 2026 Piyomaru Software, All Rights Reserved
—

set myAddress to "東京都新宿区西新宿2丁目8−1"

set gRes to my geocode(myAddress)
set {aLat, Along} to parseByDelim(gRes, "|") of me
–> {"35.6894863", "139.6917052"}

on geocode(addressString)
  set swiftSource to "
import CoreLocation
import Foundation

let address = \"$TARGET$\"
let geocoder = CLGeocoder()
var completed = false
var resultString = \"Error: Timeout or Access Denied\"

geocoder.geocodeAddressString(address) { placemarks, error in
if let loc = placemarks?.first?.location {
resultString = \"\\(loc.coordinate.latitude)|\\(loc.coordinate.longitude)\"
} else {
resultString = \"Error: \\(error?.localizedDescription ?? \"Unknown\")\"
}
completed = true
}

// 5秒間、結果を待機しながらランループを回す
let timeout = Date(timeIntervalSinceNow: 5.0)
while !completed && Date() < timeout {
RunLoop.current.run(mode: .default, before: Date(timeIntervalSinceNow: 0.00001))
}

print(resultString)
"

  return my runSwift(swiftSource, addressString)
end geocode

on runSwift(source, targetValue)
  set finalCode to my replaceText("$TARGET$", targetValue, source)
  
try
    — ヒアドキュメントで実行
    
return do shell script "swift – <<’EOF’" & return & finalCode & return & "EOF"
  on error errMsg
    return "実行エラー: " & errMsg
  end try
end runSwift

on replaceText(s, r, t)
  set AppleScript’s text item delimiters to s
  
set textItems to every text item of t
  
set AppleScript’s text item delimiters to r
  
set res to textItems as string
  
set AppleScript’s text item delimiters to ""
  
return res
end replaceText

on parseByDelim(aData, aDelim)
  set curDelim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to aDelim
  
set dList to text items of aData
  
set AppleScript’s text item delimiters to curDelim
  
return dList
end parseByDelim

★Click Here to Open This Script 

AppleScript名:緯度経度から住所を返す(Swift版).scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2026/03/16
—
–  Copyright © 2026 Piyomaru Software, All Rights Reserved
—

— サンプル座標(東京都庁付近)
set myCoords to "35.6894863|139.6917052"
set gRes to my reverseGeocode(myCoords)
–> "東京都新宿区東京都庁"

———————————————————
— ハンドラ: 緯度|経度 -> 住所
———————————————————
on reverseGeocode(latLonString)
  set swiftSource to "
import CoreLocation
import Foundation

let input = \"$TARGET$\"
let parts = input.components(separatedBy: \"|\")

guard parts.count == 2,
let lat = Double(parts[0].trimmingCharacters(in: .whitespaces)),
let lon = Double(parts[1].trimmingCharacters(in: .whitespaces))
else {
print(\"Error: Invalid input format\")
exit(1)
}

let location = CLLocation(latitude: lat, longitude: lon)
let geocoder = CLGeocoder()
var completed = false
var resultString = \"Error: Timeout or No Data\"

geocoder.reverseGeocodeLocation(location) { placemarks, error in
if let p = placemarks?.first {
// 都道府県 + 市区町村 + 地番・ビル名などを結合
let addr = \"\\(p.administrativeArea ?? \"\")\\(p.locality ?? \"\")\\(p.name ?? \"\")\"
resultString = addr
} else {
resultString = \"Error: \\(error?.localizedDescription ?? \"Unknown\")\"
}
completed = true
}

// 5秒間、結果が返るまでランループを回す
let timeout = Date(timeIntervalSinceNow: 5.0)
while !completed && Date() < timeout {
RunLoop.current.run(mode: .default, before: Date(timeIntervalSinceNow: 0.00001))
}

print(resultString)
"

  return my runSwift(swiftSource, latLonString)
end reverseGeocode

———————————————————
— Swift実行サブシステム
———————————————————
on runSwift(source, targetValue)
  set finalCode to my replaceText("$TARGET$", targetValue, source)
  
try
    — ファイルを作らず標準入力から実行
    
return do shell script "swift – <<’EOF’" & return & finalCode & return & "EOF"
  on error errMsg
    return "Error: " & errMsg
  end try
end runSwift

on replaceText(s, r, t)
  set AppleScript’s text item delimiters to s
  
set textItems to every text item of t
  
set AppleScript’s text item delimiters to r
  
set res to textItems as string
  
set AppleScript’s text item delimiters to ""
  
return res
end replaceText

★Click Here to Open This Script 

(Visited 4 times, 4 visits today)
Posted in geolocation Swift | Tagged 26.0savvy | Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

電子書籍(PDF)をオンラインストアで販売中!

Google Search

Popular posts

  • macOS 26, Tahoe
  • 【続報】macOS 15.5で特定ファイル名パターンのfileをaliasにcastすると100%クラッシュするバグ
  • Xcode上のAppleScriptObjCのプログラムから、Xcodeのログ欄へのメッセージ出力を実行
  • Script Debuggerがフリーダウンロードで提供されることに
  • AppleScript Dropletのバグっぽい動作が「復活」(macOS 15.5β)
  • macOS 26, 15.5でShortcuts.app「AppleScriptを実行」アクションのバグが修正される
  • Numbersで選択範囲のdateの年を+1する
  • Appleに買収されたPixelmator ProがAppleとしての初アップデート
  • Dock Menu
  • Applicationのactivateを記録する v2
  • シンプルな文字置換
  • macOS 15.5beta5(24F74)でaliasのキャスティングバグが修正された???
  • Claris FileMaker Pro 2025(v22)がリリースされた
  • Apple Creator Studioに含まれるKeynote/Pages/Numbersは新バージョン?
  • macOS 15.7.2 スクリプトメニューから実行できなくなった地図系ライブラリ?
  • 画像をAppleScriptでアスキーアート化
  • NaturalLanguage.frameworkを用いて日本語テキストの形態素解析を行う
  • macOS(Mac OS X/OS X)上のAppleScriptの歴史
  • Adobe InDesignのAppleScript実行エンジンがCarbonからCocoaベースに書き換えられる
  • 開始時刻から終了時刻までhh:mm形式の文字列を15分単位でリスト出力

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1391) 10.14savvy (587) 10.15savvy (439) 11.0savvy (283) 12.0savvy (212) 13.0savvy (204) 14.0savvy (159) 15.0savvy (170) 26.0savvy (44) CotEditor (68) Finder (53) Keynote (122) NSAlert (61) NSArray (51) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (53) NSDictionary (28) NSFileManager (23) NSFont (21) NSImage (41) NSJSONSerialization (21) NSMutableArray (63) NSMutableDictionary (22) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (119) NSURL (98) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (80) Pages (58) Safari (44) Script Editor (27) WKUserContentController (21) WKUserScript (20) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • Beginner
  • Benchmark
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • check sum
  • Clipboard
  • Cocoa-AppleScript Applet
  • Code Sign
  • Color
  • Custom Class
  • date
  • dialog
  • diff
  • drive
  • Droplet
  • exif
  • file
  • File path
  • filter
  • folder
  • Font
  • Font
  • GAME
  • geolocation
  • GUI
  • GUI Scripting
  • Hex
  • History
  • How To
  • iCloud
  • Icon
  • Image
  • Input Method
  • Internet
  • iOS App
  • JavaScript
  • JSON
  • JXA
  • Keychain
  • Keychain
  • Language
  • Library
  • list
  • Locale
  • Localize
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Newt On Project
  • NFC
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • parallel processing
  • PDF
  • Peripheral
  • process
  • PRODUCTS
  • QR Code
  • Raw AppleEvent Code
  • Record
  • rectangle
  • recursive call
  • regexp
  • Release
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • Review
  • RTF
  • Sandbox
  • Screen Saver
  • Script Libraries
  • Scripting Additions
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • Swift
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2026年3月
  • 2026年2月
  • 2026年1月
  • 2025年12月
  • 2025年11月
  • 2025年10月
  • 2025年9月
  • 2025年8月
  • 2025年7月
  • 2025年6月
  • 2025年5月
  • 2025年4月
  • 2025年3月
  • 2025年2月
  • 2025年1月
  • 2024年12月
  • 2024年11月
  • 2024年10月
  • 2024年9月
  • 2024年8月
  • 2024年7月
  • 2024年6月
  • 2024年5月
  • 2024年4月
  • 2024年3月
  • 2024年2月
  • 2024年1月
  • 2023年12月
  • 2023年11月
  • 2023年10月
  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

https://piyomarusoft.booth.pm/items/301502

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org

Forum Posts

  • 人気のトピック
  • 返信がないトピック

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC