アラートダイアログを作成し、その上にMap Viewを表示して位置座標の選択を行うAppleScriptです。
Map Viewを使用するためには、インターネット接続が必要です。
もしこれをAppleScriptのコマンドのように表現するなら「choose geo location」とかいうコマンドになるでしょうか。本当は地図.appのように地図中でクリックした場所にピンを打って選択箇所を明示するようなものを考えていたのですが、実際にASだけで作ろうとすると難しいものがありそうで。
こうした「ざっくり場所を選ぶ」ダイアログのほか、複数の地点をピンで表示し、そのうちのどれかを地図上で選択するといったコマンドがあると使いでがありそうです。
AppleScript名:アラートダイアログ上のMap Viewを表示 |
— Created 2019-02-14 by Takaaki Naganoya — 2019 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" use framework "MapKit" use framework "AppKit" property |NSURL| : a reference to current application’s |NSURL| property NSData : a reference to current application’s NSData property MKMapView : a reference to current application’s MKMapView property NSURLRequest : a reference to current application’s NSURLRequest property NSURLConnection : a reference to current application’s NSURLConnection property theResult : 0 property returnCode : 0 set nRes to hasInternetConnection("http://www.google.com") of me if nRes = false then error "No Internet Connection…." –地図表示初期座標。一般的にはWiFi経由でAssistive-GPSから現在位置を拾って指定 set aLong to 130.55723797 set aLat to 31.57868838 set paramObj to {myMessage:"場所の選択", mySubMessage:"目標の場所を地図中央に入れてください", aLongitude:aLong, aLatitude:aLat} my performSelectorOnMainThread:"chooseCoordinate:" withObject:(paramObj) waitUntilDone:true return theResult –> {latitude:31.57868838, longitude:130.55723797} on chooseCoordinate:paramObj set aMainMes to myMessage of paramObj set aSubMes to mySubMessage of paramObj set aLong to aLongitude of paramObj set aLat to aLatitude of paramObj –MKMapViewをつくる set aMapView to MKMapView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, 500, 300)) tell aMapView its setMapType:(current application’s MKMapTypeStandard) its setZoomEnabled:true its setScrollEnabled:true its setPitchEnabled:true its setRotateEnabled:true its setShowsCompass:true its setShowsZoomControls:true its setShowsScale:true its setShowsUserLocation:true set aLocation to current application’s CLLocationCoordinate2DMake(aLat, aLong) its setCenterCoordinate:aLocation zoomLevel:17 animated:false its setDelegate:me end tell — set up alert set theAlert to current application’s NSAlert’s alloc()’s init() tell theAlert its setMessageText:aMainMes its setInformativeText:aSubMes its addButtonWithTitle:"OK" its addButtonWithTitle:"Cancel" its setAccessoryView:aMapView end tell — show alert in modal loop current application’s NSRunningApplication’s currentApplication()’s activateWithOptions:(current application’s NSApplicationActivateIgnoringOtherApps) set returnCode to theAlert’s runModal() if returnCode = (current application’s NSAlertSecondButtonReturn) then error number -128 set (my theResult) to (aMapView’s centerCoordinate()) as record end chooseCoordinate: –Internet Connection Check on hasInternetConnection(aURLString) set aURL to |NSURL|’s alloc()’s initWithString:aURLString set aReq to NSURLRequest’s alloc()’s initWithURL:aURL cachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:5.0 set urlRes to (NSURLConnection’s sendSynchronousRequest:aReq returningResponse:(missing value) |error|:(missing value)) if urlRes = missing value then return false else return true end if end hasInternetConnection |
More from my site
(Visited 82 times, 1 visits today)