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

タグ: 10.12savvy

Numbersから緯度経度情報を取得して地図にプロット v3(プログレスバー+セグメント)

Posted on 2月 6, 2018 by Takaaki Naganoya

Numbers書類上に記載した緯度経度情報を取得して、動的に作成したウィンドウの地図上にプロット表示するAppleScriptです。

実行には、「場所名」「緯度」「経度」がワンセットとなったNumbers書類をNumbersでオープンした状態で、本AppleScriptをスクリプトエディタ上でオープンし、Control-Command-Rを実行します。

ひととおり地図上の指定位置へのピンの作成が終わると、普通に地図アプリなどと同様に拡大や縮小、3D表示、マップ表示、航空写真表示などを切り替えてブラウズすることが可能です。

–> Demo Movie

AppleScript名:Numbersから緯度経度情報を取得して地図にプロット v3(プログレスバー+セグメント)
— Created 2017-12-20 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "MapKit"
use framework "CoreLocation"
use bPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#BridgePlus

property NSView : a reference to current application’s NSView
property NSScreen : a reference to current application’s NSScreen
property NSButton : a reference to current application’s NSButton
property SMSForder : a reference to current application’s SMSForder
property NSWindow : a reference to current application’s NSWindow
property MKMapView : a reference to current application’s MKMapView
property MKMapTypeHybrid : a reference to current application’s MKMapTypeHybrid
property MKPointAnnotation : a reference to current application’s MKPointAnnotation
property MKMapTypeSatellite : a reference to current application’s MKMapTypeSatellite
property NSWindowController : a reference to current application’s NSWindowController
property NSTitledWindowMask : a reference to current application’s NSTitledWindowMask
property MKMapTypeStandard : a reference to current application’s MKMapTypeStandard
property NSSegmentedControl : a reference to current application’s NSSegmentedControl
property NSNormalWindowLevel : a reference to current application’s NSNormalWindowLevel
property NSBackingStoreBuffered : a reference to current application’s NSBackingStoreBuffered
property NSSegmentStyleTexturedRounded : a reference to current application’s NSSegmentStyleTexturedRounded

property windisp : false
property selSeg : 0
property aMapView : missing value

–データを取得する
set locList to getDataFromNumbersDoc() of me

set aWidth to 800
set aHeight to 600

set segTitleList to {"Map", "Satellite", "Satellite + Map"}
set tableTitle to retCurNumbersDocsTableName() of me
dispMapView(aWidth, aHeight, tableTitle, "OK", 180, locList, segTitleList) of me

on dispMapView(aWidth as integer, aHeight as integer, aTitle as text, aButtonMSG as text, timeOutSecs as number, locList, segTitleList)
  –Check If this script runs in foreground
  
if not (current application’s NSThread’s isMainThread()) as boolean then
    error "This script must be run from the main thread (Command-Control-R in Script Editor)."
  end if
  
  
set selSeg to 0
  
set (my windisp) to true
  
  
  
  
–NSViewをつくる
  
set aNSView to NSView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aHeight, aWidth))
  
  
aNSView’s setNeedsDisplay:true
  
  
set aWin to makeWinWithView(aNSView, aWidth, aHeight, aTitle, 1.0)
  
  
set wController to NSWindowController’s alloc()
  
wController’s initWithWindow:aWin
  
wController’s showWindow:me
  
aWin’s makeKeyAndOrderFront:me –Windowを表示状態に
  
  
  
–Progress Barをつくる
  
set aPBar to current application’s NSProgressIndicator’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 40, aWidth, 40))
  
aPBar’s setMaxValue:(length of locList)
  
aPBar’s setMinValue:1
  
aPBar’s setIndeterminate:false
  
aPBar’s setControlSize:(current application’s NSProgressIndicatorPreferredLargeThickness)
  
aPBar’s setDoubleValue:(1.0 as real)
  
aNSView’s addSubview:aPBar
  
  
  
–MKMapViewをつくる
  
set aMapView to MKMapView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 40, aWidth, aHeight – 40))
  
aMapView’s setMapType:(current application’s MKMapTypeStandard)
  
  
aMapView’s setZoomEnabled:true
  
aMapView’s setScrollEnabled:true
  
aMapView’s setPitchEnabled:true
  
aMapView’s setRotateEnabled:false
  
aMapView’s setShowsCompass:true
  
aMapView’s setShowsZoomControls:true
  
aMapView’s setShowsScale:true
  
aMapView’s setShowsUserLocation:true
  
aMapView’s setDelegate:me
  
  
  
–MapにPinを追加
  
set aCount to 1
  
repeat with i in locList
    (aPBar’s setDoubleValue:(aCount as real)) –Update Progress Bar
    
    
copy i to {tmpAdr, tmpLat, tmpLong}
    
    
set aLocation to current application’s CLLocationCoordinate2DMake(tmpLat, tmpLong)
    
set anAnnotation to MKPointAnnotation’s alloc()’s init()
    (
anAnnotation’s setCoordinate:aLocation)
    (
anAnnotation’s setTitle:tmpAdr)
    (
aMapView’s addAnnotation:anAnnotation)
    
    
set aCount to aCount + 1
  end repeat
  
  
aPBar’s removeFromSuperview() –Remove Progress Bar
  
  
–Segmented Controlをつくる
  
set aSeg to makeSegmentedControl(segTitleList, aWidth, aHeight) of me
  
aNSView’s addSubview:aSeg
  
  
–MapViewをWindow上に表示  
  
copy middle item of locList to {tmpAdr, tmpLat, tmpLong}
  
set aLocation to current application’s CLLocationCoordinate2DMake(tmpLat, tmpLong)
  
aMapView’s setCenterCoordinate:aLocation zoomLevel:7 animated:false
  
aNSView’s addSubview:aMapView
  
  
–Buttonをつくる
  
set bButton to (NSButton’s alloc()’s initWithFrame:(current application’s NSMakeRect(aWidth – 100, 0, 100, 40)))
  
bButton’s setTitle:aButtonMSG
  
bButton’s setButtonType:(current application’s NSMomentaryLightButton)
  
bButton’s setBezelStyle:(current application’s NSRoundedBezelStyle)
  
bButton’s setKeyEquivalent:(return)
  
bButton’s setTarget:me
  
bButton’s setAction:("clicked:")
  
aNSView’s addSubview:bButton
  
  
aWin’s makeFirstResponder:aMapView
  
  
set aCount to timeOutSecs * 10 –timeout seconds * 10
  
repeat aCount times
    if (my windisp) = false then
      exit repeat
    end if
    
delay 0.1
  end repeat
  
  
my closeWin:aWin
  
end dispMapView

–Button Clicked Event Handler
on clicked:aSender
  set (my windisp) to false
end clicked:

–make Window for Input
on makeWinWithView(aView, aWinWidth, aWinHeight, aTitle, alphaV)
  set aScreen to NSScreen’s mainScreen()
  
set aFrame to {{0, 0}, {aWinWidth, aWinHeight}}
  
set aBacking to NSTitledWindowMask
  
set aDefer to NSBackingStoreBuffered
  
  
— Window
  
set aWin to NSWindow’s alloc()
  (
aWin’s initWithContentRect:aFrame styleMask:aBacking backing:aDefer defer:false screen:aScreen)
  
  
aWin’s setTitle:aTitle
  
aWin’s setDelegate:me
  
aWin’s setDisplaysWhenScreenProfileChanges:true
  
aWin’s setHasShadow:true
  
aWin’s setIgnoresMouseEvents:false
  
aWin’s setLevel:(NSNormalWindowLevel)
  
aWin’s setOpaque:false
  
aWin’s setAlphaValue:alphaV –append
  
aWin’s setReleasedWhenClosed:true
  
aWin’s |center|()
  
aWin’s makeKeyAndOrderFront:(me)
  
  
— Set Custom View
  
aWin’s setContentView:aView
  
  
return aWin
end makeWinWithView

–close win
on closeWin:aWindow
  repeat with n from 10 to 1 by -1
    (aWindow’s setAlphaValue:n / 10)
    
delay 0.02
  end repeat
  
aWindow’s |close|()
end closeWin:

on makeSegmentedControl(titleList, aWidth, aHeight)
  set aLen to length of titleList
  
  
set aSeg to NSSegmentedControl’s alloc()’s init()
  
aSeg’s setSegmentCount:aLen
  
  
set aCount to 0
  
repeat with i in titleList
    set j to contents of i
    (
aSeg’s setLabel:j forSegment:aCount)
    
set aCount to aCount + 1
  end repeat
  
  
aSeg’s setTranslatesAutoresizingMaskIntoConstraints:false
  
aSeg’s setSegmentStyle:(NSSegmentStyleTexturedRounded)
  
aSeg’s setFrame:(current application’s NSMakeRect(10, 5, 260, 30))
  
aSeg’s setTrackingMode:0
  
aSeg’s setTarget:me
  
aSeg’s setAction:"clickedSeg:"
  
aSeg’s setSelectedSegment:0
  
  
return aSeg
end makeSegmentedControl

–Numbersでオープン中の書類の選択中のシートの表1からデータを取得して2D Listに
on getDataFromNumbersDoc()
  
  
load framework
  
  
tell application "Numbers"
    if (count every document) = 0 then return false
    
    
tell front document
      if (count every sheet) = 0 then return false
      
      
tell active sheet
        tell table 1
          set colCount to column count
          
set rowCount to row count
          
set headerCount to header row count
          
set footerCount to footer row count
          
          
set dList to value of every cell of cell range
        end tell
      end tell
      
    end tell
  end tell
  
  
–Convert 1D List to 2D List
  
set bList to (SMSForder’s subarraysFrom:dList groupedBy:colCount |error|:(missing value)) as list
  
set sItem to 1 + headerCount
  
set eItem to rowCount – footerCount
  
set cList to items sItem thru eItem of bList
  
  
return cList
  
end getDataFromNumbersDoc

on retCurNumbersDocsTableName()
  tell application "Numbers"
    tell front document
      tell active sheet
        tell table 1
          return name
        end tell
      end tell
    end tell
  end tell
end retCurNumbersDocsTableName

on clickedSeg:aSender
  set aSel to aSender’s selectedSegment()
  
set selSeg to (aSel + 1)
  
set mapList to {MKMapTypeStandard, MKMapTypeSatellite, MKMapTypeHybrid}
  
set curMap to contents of item selSeg of mapList
  
aMapView’s setMapType:(curMap)
end clickedSeg:

★Click Here to Open This Script 

Posted in Require Control-Command-R to run | Tagged 10.11savvy 10.12savvy 10.13savvy Numbers | Leave a comment

指定IPアドレスの情報を取得して地図にプロット v3(プログレスバー+セグメント)

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定IPアドレスの情報を取得して地図にプロット v3(プログレスバー+セグメント)
— Created 2017-12-20 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "MapKit"
use framework "CoreLocation"
use bPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#BridgePlus

property |NSURL| : a reference to current application’s |NSURL|
property NSData : a reference to current application’s NSData
property NSView : a reference to current application’s NSView
property NSScreen : a reference to current application’s NSScreen
property NSButton : a reference to current application’s NSButton
property SMSForder : a reference to current application’s SMSForder
property NSWindow : a reference to current application’s NSWindow
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 MKMapTypeHybrid : a reference to current application’s MKMapTypeHybrid
property MKPointAnnotation : a reference to current application’s MKPointAnnotation
property NSJSONSerialization : a reference to current application’s NSJSONSerialization
property MKMapTypeSatellite : a reference to current application’s MKMapTypeSatellite
property NSWindowController : a reference to current application’s NSWindowController
property NSTitledWindowMask : a reference to current application’s NSTitledWindowMask
property MKMapTypeStandard : a reference to current application’s MKMapTypeStandard
property NSSegmentedControl : a reference to current application’s NSSegmentedControl
property NSNormalWindowLevel : a reference to current application’s NSNormalWindowLevel
property NSBackingStoreBuffered : a reference to current application’s NSBackingStoreBuffered
property NSSegmentStyleTexturedRounded : a reference to current application’s NSSegmentStyleTexturedRounded

property windisp : false
property selSeg : 0
property aMapView : missing value

set nRes to hasInternetConnection() of me
if nRes = false then
  display dialog "No Internet Connection…." buttons {"OK"} default button 1 with icon 0
  
return
end if

set aClip to the clipboard
set anIP to text returned of (display dialog "Input IP address to find its location" default answer aClip)

set windisp to false
set aInfo to getIPAddressInfoFreeGeoIP(anIP) of me

if aInfo = missing value then
  display dialog "Network Error"
  
return
end if

set aLong to (longitude of (aInfo as record)) as real
set aLat to (latitude of (aInfo as record)) as real
set aZip to zip_code of (aInfo as record)
set locList to {{aZip, aLat, aLong}}

set aWidth to 800
set aHeight to 600

set segTitleList to {"Map", "Satellite", "Satellite + Map"}
dispMapView(aWidth, aHeight, aZip, "OK", 180, locList, segTitleList) of me

on dispMapView(aWidth as integer, aHeight as integer, aTitle as text, aButtonMSG as text, timeOutSecs as number, locList, segTitleList)
  –Check If this script runs in foreground
  
if not (current application’s NSThread’s isMainThread()) as boolean then
    error "This script must be run from the main thread (Command-Control-R in Script Editor)."
  end if
  
  
set selSeg to 0
  
set (my windisp) to true
  
  
  
  
–NSViewをつくる
  
set aNSView to NSView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aHeight, aWidth))
  
  
aNSView’s setNeedsDisplay:true
  
  
set aWin to makeWinWithView(aNSView, aWidth, aHeight, aTitle, 1.0)
  
  
set wController to NSWindowController’s alloc()
  
wController’s initWithWindow:aWin
  
wController’s showWindow:me
  
aWin’s makeKeyAndOrderFront:me –Windowを表示状態に
  
  
  
–Progress Barをつくる
  
set aPBar to current application’s NSProgressIndicator’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 40, aWidth, 40))
  
aPBar’s setMaxValue:(length of locList)
  
aPBar’s setMinValue:1
  
aPBar’s setIndeterminate:false
  
aPBar’s setControlSize:(current application’s NSProgressIndicatorPreferredLargeThickness)
  
aPBar’s setDoubleValue:(1.0 as real)
  
aNSView’s addSubview:aPBar
  
  
  
–MKMapViewをつくる
  
set aMapView to MKMapView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 40, aWidth, aHeight – 40))
  
aMapView’s setMapType:(current application’s MKMapTypeStandard)
  
  
aMapView’s setZoomEnabled:true
  
aMapView’s setScrollEnabled:true
  
aMapView’s setPitchEnabled:true
  
aMapView’s setRotateEnabled:false
  
aMapView’s setShowsCompass:true
  
aMapView’s setShowsZoomControls:true
  
aMapView’s setShowsScale:true
  
aMapView’s setShowsUserLocation:true
  
aMapView’s setDelegate:me
  
  
  
–MapにPinを追加
  
set aCount to 1
  
repeat with i in locList
    (aPBar’s setDoubleValue:(aCount as real)) –Update Progress Bar
    
    
copy i to {tmpAdr, tmpLat, tmpLong}
    
    
set aLocation to current application’s CLLocationCoordinate2DMake(tmpLat, tmpLong)
    
set anAnnotation to MKPointAnnotation’s alloc()’s init()
    (
anAnnotation’s setCoordinate:aLocation)
    (
anAnnotation’s setTitle:tmpAdr)
    (
aMapView’s addAnnotation:anAnnotation)
    
    
set aCount to aCount + 1
  end repeat
  
  
aPBar’s removeFromSuperview() –Remove Progress Bar
  
  
–Segmented Controlをつくる
  
set aSeg to makeSegmentedControl(segTitleList, aWidth, aHeight) of me
  
aNSView’s addSubview:aSeg
  
  
–MapViewをWindow上に表示  
  
copy middle item of locList to {tmpAdr, tmpLat, tmpLong}
  
set aLocation to current application’s CLLocationCoordinate2DMake(tmpLat, tmpLong)
  
aMapView’s setCenterCoordinate:aLocation zoomLevel:7 animated:false
  
aNSView’s addSubview:aMapView
  
  
–Buttonをつくる
  
set bButton to (NSButton’s alloc()’s initWithFrame:(current application’s NSMakeRect(aWidth – 100, 0, 100, 40)))
  
bButton’s setTitle:aButtonMSG
  
bButton’s setButtonType:(current application’s NSMomentaryLightButton)
  
bButton’s setBezelStyle:(current application’s NSRoundedBezelStyle)
  
bButton’s setKeyEquivalent:(return)
  
bButton’s setTarget:me
  
bButton’s setAction:("clicked:")
  
aNSView’s addSubview:bButton
  
  
aWin’s makeFirstResponder:aMapView
  
  
set aCount to timeOutSecs * 10 –timeout seconds * 10
  
repeat aCount times
    if (my windisp) = false then
      exit repeat
    end if
    
delay 0.1
  end repeat
  
  
my closeWin:aWin
  
end dispMapView

–Button Clicked Event Handler
on clicked:aSender
  set (my windisp) to false
end clicked:

–make Window for Input
on makeWinWithView(aView, aWinWidth, aWinHeight, aTitle, alphaV)
  set aScreen to NSScreen’s mainScreen()
  
set aFrame to {{0, 0}, {aWinWidth, aWinHeight}}
  
set aBacking to NSTitledWindowMask
  
set aDefer to NSBackingStoreBuffered
  
  
— Window
  
set aWin to NSWindow’s alloc()
  (
aWin’s initWithContentRect:aFrame styleMask:aBacking backing:aDefer defer:false screen:aScreen)
  
  
aWin’s setTitle:aTitle
  
aWin’s setDelegate:me
  
aWin’s setDisplaysWhenScreenProfileChanges:true
  
aWin’s setHasShadow:true
  
aWin’s setIgnoresMouseEvents:false
  
aWin’s setLevel:(NSNormalWindowLevel)
  
aWin’s setOpaque:false
  
aWin’s setAlphaValue:alphaV –append
  
aWin’s setReleasedWhenClosed:true
  
aWin’s |center|()
  
aWin’s makeKeyAndOrderFront:(me)
  
  
— Set Custom View
  
aWin’s setContentView:aView
  
  
return aWin
end makeWinWithView

–close win
on closeWin:aWindow
  repeat with n from 10 to 1 by -1
    (aWindow’s setAlphaValue:n / 10)
    
delay 0.02
  end repeat
  
aWindow’s |close|()
end closeWin:

on makeSegmentedControl(titleList, aWidth, aHeight)
  set aLen to length of titleList
  
  
set aSeg to NSSegmentedControl’s alloc()’s init()
  
aSeg’s setSegmentCount:aLen
  
  
set aCount to 0
  
repeat with i in titleList
    set j to contents of i
    (
aSeg’s setLabel:j forSegment:aCount)
    
set aCount to aCount + 1
  end repeat
  
  
aSeg’s setTranslatesAutoresizingMaskIntoConstraints:false
  
aSeg’s setSegmentStyle:(NSSegmentStyleTexturedRounded)
  
aSeg’s setFrame:(current application’s NSMakeRect(10, 5, 260, 30))
  
aSeg’s setTrackingMode:0
  
aSeg’s setTarget:me
  
aSeg’s setAction:"clickedSeg:"
  
aSeg’s setSelectedSegment:0
  
  
return aSeg
end makeSegmentedControl

on clickedSeg:aSender
  set aSel to aSender’s selectedSegment()
  
set selSeg to (aSel + 1)
  
set mapList to {MKMapTypeStandard, MKMapTypeSatellite, MKMapTypeHybrid}
  
set curMap to contents of item selSeg of mapList
  
aMapView’s setMapType:(curMap)
end clickedSeg:

–http://freegeoip.net
on getIPAddressInfoFreeGeoIP(IPAddress)
  try
    with timeout of 10 seconds
      set link to "http://freegeoip.net/json/" & IPAddress
      
set theURL to |NSURL|’s URLWithString:link
      
set jsonData to NSData’s dataWithContentsOfURL:theURL
      
set aJsonDict to (NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value))
      
return aJsonDict
    end timeout
  on error
    return missing value
  end try
end getIPAddressInfoFreeGeoIP

–Internet Connection Check
on hasInternetConnection()
  set aURL to |NSURL|’s alloc()’s initWithString:"http://www.google.com"
  
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

★Click Here to Open This Script 

Posted in Require Control-Command-R to run | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

JeditΩの最前面のドキュメントのプロパティ取得

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:JeditΩの最前面のドキュメントのプロパティ取得
tell application id "jp.co.artman21.JeditOmega"
  tell front document
    properties
  end tell
end tell

–> {rich text:true, line endings:LF, path:"/Users/maro/Library/Mobile Documents/iCloud~jp~co~artman21~JeditOmega/Documents/名称未設定5.rtf", selected character range:{loc:21, len:0}, encoding:missing value, class:document, selected attribute range:{loc:2, len:0}, name:"名称未設定5", default attributes:{forecolor:{0, 0, 0}, backcolor:{65535, 65535, 65535}, charfont:"Helvetica", charsize:12.0}, modified:false, selected paragraph range:{loc:1, len:1}, selected text:"", text:"This is Test String.", document type:"リッチテキスト書式(.rtf)"}

–> {rich text:false, line endings:LF, path:"/Users/maro/Library/Mobile Documents/iCloud~jp~co~artman21~JeditOmega/Documents/名称未設定5.txt", selected character range:{loc:21, len:0}, encoding:missing value, class:document, selected attribute range:{loc:2, len:0}, name:"名称未設定5.rtf", default attributes:{forecolor:{0, 0, 0}, backcolor:{65535, 65535, 65535}, charfont:"Helvetica", charsize:12.0}, modified:false, selected paragraph range:{loc:1, len:1}, selected text:"", text:"This is Test String.", document type:"プレーンテキスト書類"}

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy JeditΩ | Leave a comment

文字種別にカウントする v2.1(JeditΩ版)

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:文字種別にカウントする v2.1(JeditΩ版)
— Created 2018-1-11 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
–http://piyocast.com/as/archives/5111

property NSString : a reference to current application’s NSString
property NSNumber : a reference to current application’s NSNumber
property NSDictionary : a reference to current application’s NSDictionary
property NSCountedSet : a reference to current application’s NSCountedSet
property NSMutableArray : a reference to current application’s NSMutableArray
property NSNumberFormatter : a reference to current application’s NSNumberFormatter
property NSRegularExpressionSearch : a reference to current application’s NSRegularExpressionSearch
property NSNumberFormatterRoundUp : a reference to current application’s NSNumberFormatterRoundUp

set aRes to getEditorText() of me
if aRes = false then return

set myPath to retFrontDocsPath() of me
if myPath = missing value then return

set aRec to detectCharKindRatio(aRes) of me
set bRes to retFormattedStr(aRec) of me
makeNewDocument of me given parameter:(myPath & return & return & bRes)

on detectCharKindRatio(aStr as string)
  set theCountedSet to NSCountedSet’s alloc()’s initWithArray:(characters of aStr)
  
set theEnumerator to theCountedSet’s objectEnumerator()
  
  
set cCount to 0
  
set hCount to 0
  
set kCount to 0
  
set oCount to 0
  
set lfCount to 0
  
set scCount to 0
  
set anCount to 0
  
  
set totalC to length of aStr
  
set otherList to {}
  
  
repeat
    set aValue to theEnumerator’s nextObject()
    
if aValue is missing value then exit repeat
    
    
set aStr to aValue as string
    
set tmpCount to (theCountedSet’s countForObject:aValue)
    
    
set s1Res to chkKanji(aStr) of me
    
set s2Res to chkKatakana(aStr) of me
    
set s3Res to chkHiragana(aStr) of me
    
set s4Res to chkLineFeed(aStr) of me
    
set s5Res to chkSpecialSign(aStr) of me
    
set s6Res to chkAlphaNumeric(aStr)
    
    
if s1Res = true then
      set cCount to cCount + tmpCount
    else if s2Res = true then
      set kCount to kCount + tmpCount
    else if s3Res = true then
      set hCount to hCount + tmpCount
    else if s4Res = true then
      set lfCount to lfCount + tmpCount
    else if s5Res = true then
      set scCount to scCount + tmpCount
    else if s6Res = true then
      set anCount to anCount + tmpCount
    else
      set oCount to oCount + tmpCount
      
set the end of otherList to aStr
    end if
  end repeat
  
  
set ckRes to roundingUp((cCount / totalC) * 100, 1) of me
  
set kkRes to roundingUp((kCount / totalC) * 100, 1) of me
  
set hgRes to roundingUp((hCount / totalC) * 100, 1) of me
  
set otRes to roundingUp((oCount / totalC) * 100, 1) of me
  
set lfRes to roundingUp((lfCount / totalC) * 100, 1) of me
  
set scRes to roundingUp((scCount / totalC) * 100, 1) of me
  
set anRes to roundingUp((anCount / totalC) * 100, 1) of me
  
  
return {kanjiNum:cCount, kanjiRatio:ckRes, hiraganaNum:hCount, hiraganaRatio:hgRes, katakanaNum:kCount, katakanaRatio:kkRes, otherNum:oCount, otherRatio:otRes, otherContent:otherList, lineFeedCount:lfCount, lineFeedRatio:lfRes, specialSignNum:scCount, specialSignRatio:scRes, alphaNumericNum:anCount, alphaNumericRatio:anRes, totalCount:totalC}
end detectCharKindRatio

on chkKanji(aChar)
  return detectCharKind(aChar, "[一-龠]") of me
end chkKanji

on chkHiragana(aChar)
  return detectCharKind(aChar, "[ぁ-ん]") of me
end chkHiragana

on chkKatakana(aChar)
  return detectCharKind(aChar, "[ァ-ヶ]") of me
end chkKatakana

on chkLineFeed(aChar)
  return aChar is in {string id 10, string id 13, string id 13 & string id 10}
end chkLineFeed

on chkSpecialSign(aChar)
  return aChar is in {"「", "」", "『", "』", "ー", "―", "〜", "~", "!", "?", "&", "/", "《", "》", "#", "…", "・", "♪", "。", "、", ".", "々", "“", "”", "*", "(", ")", "(", ")", " ", " ", "§", "【", "】", "■", "%", "≒"}
end chkSpecialSign

on chkAlphaNumeric(aChar)
  return detectCharKind(aChar, "[a-zA-Z0-9a-zA-Z0-9]") of me –半角全角英数字
end chkAlphaNumeric

on detectCharKind(aChar, aPattern)
  set aChar to NSString’s stringWithString:aChar
  
set searchStr to NSString’s stringWithString:aPattern
  
set matchRes to aChar’s rangeOfString:searchStr options:(NSRegularExpressionSearch)
  
if matchRes’s location() = (current application’s NSNotFound) or (matchRes’s location() as number) > 9.99999999E+8 then
    return false
  else
    return true
  end if
end detectCharKind

on roundingUp(aNum, aDigit as integer)
  set a to aNum as real
  
set aFormatter to NSNumberFormatter’s alloc()’s init()
  
aFormatter’s setMaximumFractionDigits:aDigit
  
aFormatter’s setRoundingMode:(NSNumberFormatterRoundUp)
  
set aStr to aFormatter’s stringFromNumber:(NSNumber’s numberWithFloat:a)
  
return (aStr as text) as real
end roundingUp

on getEditorText()
  tell application id "jp.co.artman21.JeditOmega"
    if (count every document) = 0 then return false
    
tell front document
      return text of it
    end tell
  end tell
end getEditorText

–処理結果から出力データの組み立て
on retFormattedStr(aRec)
  set a to "漢字  :" & (repChar("■", ((kanjiRatio of aRec) div 10)) of me & "  " & (kanjiRatio of aRec) as string) & "%" & return
  
set b to "ひらがな:" & (repChar("■", ((hiraganaRatio of aRec) div 10)) of me & "  " & (hiraganaRatio of aRec) as string) & "%" & return
  
set c to "カタカナ:" & (repChar("■", ((katakanaRatio of aRec) div 10)) of me & "  " & (katakanaRatio of aRec) as string) & "%" & return
  
set d to "改行文字:" & (repChar("■", ((lineFeedRatio of aRec) div 10)) of me & "  " & (lineFeedRatio of aRec) as string) & "%" & return
  
set e to "特殊記号:" & (repChar("■", ((specialSignRatio of aRec) div 10)) of me & "  " & (specialSignRatio of aRec) as string) & "%" & return
  
set f to "英数字 :" & (repChar("■", ((alphaNumericRatio of aRec) div 10)) of me & "  " & (alphaNumericRatio of aRec) as string) & "%" & return & return
  
set g to ("総文字数:" & encodeJapaneseNumText(totalCount of aRec) & " 文字。 400字詰め原稿用紙で約 " & ((totalCount of aRec) div 400) as string) & " 枚分" & return
  
set all to a & b & c & d & e & f & g
  
return all
end retFormattedStr

on repChar(aChar, aTimes)
  set outStr to ""
  
repeat aTimes times
    set outStr to outStr & aChar
  end repeat
  
return outStr
end repChar

–数字文字列を日本語数値表現文字列に変換
on encodeJapaneseNumText(aText as string)
  set dotText to "." as string
  
set upperDigit to ""
  
set lowerDigit to ""
  
  
–小数点の処理
  
if dotText is in aText then
    set b to offset of dotText in aText
    
set upperDigit to characters 1 thru (b – 1) of aText
    
set upperDigit to upperDigit as string
    
set lowerDigit to characters b thru -1 of aText
    
set lowerDigit to lowerDigit as string
  else
    set upperDigit to aText
  end if
  
  
set scaleList3 to {"", "万", "億", "兆", "京", "垓", "丈", "壌", "溝", "砂", "正", "載", "極", "恒河沙", "阿僧梢", "那由他", "不可思議", "無量大数"}
  
set splitDigit to 4
  
set nList to splitByDigit(upperDigit, splitDigit) of me
  
set nList to reverse of nList
  
  
set resText to ""
  
set digCount to 1
  
repeat with i in nList
    set b to (contents of i) as number
    
if b is not equal to 0 then
      set resText to (b as text) & item digCount of scaleList3 & resText
    end if
    
set digCount to digCount + 1
  end repeat
  
  
return resText & lowerDigit
  
end encodeJapaneseNumText

–指定桁数で区切る
on splitByDigit(a, splitDigit)
  set aList to characters of a
  
set aList to reverse of aList
  
  
set resList to {}
  
set tempT to ""
  
set tempC to 1
  
repeat with i in aList
    set tempT to contents of i & tempT
    
if tempC mod splitDigit = 0 then
      set resList to {tempT} & resList
      
set tempT to ""
    end if
    
set tempC to tempC + 1
  end repeat
  
  
if tempT is not equal to "" then
    set resList to {tempT} & resList
  end if
  
  
resList
  
end splitByDigit

on makeNewDocument given parameter:aStr
  tell application id "jp.co.artman21.JeditOmega"
    set aDoc to make new document with properties {text:aStr}
  end tell
end makeNewDocument

on retFrontDocsPath()
  tell application id "jp.co.artman21.JeditOmega"
    tell front document
      return path
    end tell
  end tell
end retFrontDocsPath

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy JeditΩ | Leave a comment

JeditΩで新規ドキュメント作成

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:JeditΩで新規ドキュメント作成
set aCon to "This is Test String."
set newDoc to makeNewDocumentWithJeditOmega(aCon, false) of me –make new plain text
–makeADocToPlan(newDoc) of me

on makeNewDocumentWithJeditOmega(aCon)
  tell application id "jp.co.artman21.JeditOmega"
    set aDoc to make new document with properties {text:aCon}
    
activate
    
return aDoc
  end tell
end makeNewDocumentWithJeditOmega

on makeADocToPlan(aDocRef)
  tell application id "jp.co.artman21.JeditOmega"
    tell aDocRef
      set rich text to false
    end tell
  end tell
end makeADocToPlan

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy JeditΩ | Leave a comment

各画面でムービーを全画面再生

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:各画面でムービーを全画面再生
tell application "QuickTime Player"
  activate
  
set current time of every document to 0
  
present every document
  
play every document
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

QuickTime Player X経由でムービー情報を取得

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:QuickTime Player X経由でムービー情報を取得

–QuickTime Player Xでムービーの情報を取得
tell application id "com.apple.QuickTimePlayerX"
  tell document 1
    properties
    
–> {size:59828718, volume:1.0, modified:false, current audio compression:missing value, name:"戦場の絆 17_07_31 17_09 リボー・コロニー(R) 4VS4 Aクラス.mp4", current microphone:missing value, output muted:false, duration:305.203077777778, current movie compression:missing value, current screen compression:missing value, data rate:196029, current camera:missing value, preview resolution:false, playing:true, class:document, file:file "Cherry:Users:me:Movies:戦場の絆 17_07_31 17_09 リボー・コロニー(R) 4VS4 Aクラス.mp4", natural dimensions:{1280, 720}, looping:false, time:1.6761711, rate:1.0}
  end tell
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

QuickTime Player Xで録音を開始する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:QuickTime Player Xで録音を開始する
tell application id "com.apple.QuickTimePlayerX"
  set recSound to (new audio recording)
  
  
tell recSound
    start
  end tell
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

QuickTimeムービーの縦横ドット数を取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:QuickTimeムービーの縦横ドット数を取得する
tell application "QuickTime Player"
  tell document 1
    set {aWidth, aHeight} to natural dimensions
  end tell
end tell
–>{640, 480}

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

QT Playerでムービー再生位置を先頭に(巻き戻し)

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:QT Playerでムービー再生位置を先頭に(巻き戻し)
tell application "QuickTime Player"
  tell document 1
    set current time to 0
  end tell
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

オープン中のムービーのファイルにラベルを付ける

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:オープン中のムービーのファイルにラベルを付ける
— Created 2017-10-26 by Takaaki Naganoya
— 2017 Piyomaru Software
–http://piyocast.com/as/archives/4925
tell application "QuickTime Player"
  set aDocList to every document
end tell

repeat with i in aDocList
  
  
tell application "QuickTime Player"
    tell i
      set aProp to properties
      
set aFile to (file of aProp) as alias
    end tell
  end tell
  
  
tell application "Finder"
    set label index of aFile to 5
  end tell
  
end repeat

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

ムービー再生速度を変更する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:ムービー再生速度を変更する
tell application "QuickTime Player"
  tell document 1
    set rate to 2.0
  end tell
end tell

★Click Here to Open This Script 

Posted in Object control | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

QuickTime Playerの最前面のムービーの現在表示中のコマをデスクトップにJPEG画像で保存

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:QuickTIme Playerの最前面のムービーの現在表示中のコマをデスクトップにJPEG画像で保存
— Created 2018-01-20 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
–http://piyocast.com/as/archives/5123

property NSUUID : a reference to current application’s NSUUID
property NSString : a reference to current application’s NSString
property NSImage : a reference to current application’s NSImage
property NSPasteboard : a reference to current application’s NSPasteboard
property NSJPEGFileType : a reference to current application’s NSJPEGFileType
property NSBitmapImageRep : a reference to current application’s NSBitmapImageRep

set the clipboard to "" –Clear Clipboard (=Pasteboard)

tell application "QuickTime Player"
  –No Document check
  
if (count every document) < 1 then
    display dialog "No Document…" with icon 2 buttons {"OK"} default button 1
    
return
  end if
  
  
–Audio Movie check  
  
if natural dimensions of front document = {0, 0} then
    display dialog "This is an audio file" with icon 2 buttons {"OK"} default button 1
    
return
  end if
end tell

repeat 100 times
  activate application "QuickTime Player"
  
  
tell application "System Events"
    tell process "QuickTime Player"
      click menu item 5 of menu 1 of menu bar item 4 of menu bar 1 –Edit > Copy
    end tell
  end tell
  
  
delay 0.1
  
  
set aRes to dataIsInClipboard for JPEG picture
  
if aRes = true then exit repeat
end repeat

if aRes = false then return

–クリップボードの内容をNSImageに
set aNSIMage to my getClipboardASImage()

–保存先とファイル名を求める
set targFol to POSIX path of (path to desktop)
set aUUID to NSUUID’s UUID()’s UUIDString() as text
set outPath to targFol & aUUID & ".jpg"

set aRes to saveNSImageAtPathAsJPG(aNSIMage, outPath, 1.0) of me

— クリップボードの内容をNSImageとして取り出して返す
on getClipboardASImage()
  set theNSPasteboard to NSPasteboard’s generalPasteboard()
  
set imageArray to theNSPasteboard’s readObjectsForClasses:({NSImage}) options:(missing value)
  
set targImage to imageArray’s objectAtIndex:0
  
return targImage
end getClipboardASImage

–NSImageを指定パスにJPEG形式で保存、qulityNumは0.0〜1.0。1.0は無圧縮
on saveNSImageAtPathAsJPG(anImage, outPath, qulityNum as real)
  set imageRep to anImage’s TIFFRepresentation()
  
set aRawimg to NSBitmapImageRep’s imageRepWithData:imageRep
  
set pathString to NSString’s stringWithString:outPath
  
set newPath to pathString’s stringByExpandingTildeInPath()
  
set myNewImageData to (aRawimg’s representationUsingType:(NSJPEGFileType) |properties|:{NSImageCompressionFactor:qulityNum})
  
return (myNewImageData’s writeToFile:newPath atomically:true) as boolean
end saveNSImageAtPathAsJPG

–http://ashplanning.blogspot.jp/2006/12/blog-post.html
on dataIsInClipboard for dataType
  return (clipboard info for dataType) is not {}
end dataIsInClipboard

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy QuickTime Player | Leave a comment

Numbersでセルのカラム幅を自動調整 v2

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Numbersでセルのカラム幅を自動調整 v2
— Created 2018-1-11 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
–http://piyocast.com/as/archives/5116

tell application "Numbers"
  tell front document
    tell sheet 1
      set tCount to count every table
      
if tCount = 0 then return
      
      
tell table 1
        set tableWidth to width
        
        
set cCount to count every column
        
set cWidth to width of every column
        
set aWidth to width –table width
        
        
set aveWidth to (aWidth – (first item of cWidth)) / (cCount – 1)
        
        
tell columns 2 thru cCount
          set width to aveWidth
        end tell
        
        
set wList to width of every column
      end tell
      
      
if tCount = 1 then return
      
      
set origCols to count every column of table 1
      
repeat with i from 2 to tCount
        if origCols is not equal to (count every column of table i) then
          display notification "Numbers: Column number is different in Table #" & (i as string)
          
return
        end if
      end repeat
      
      
repeat with i from 2 to tCount
        
        
tell table i
          set width to tableWidth
        end tell
        
        
set aCount to 1
        
        
tell table i
          repeat with ii from 1 to cCount
            tell column ii
              set width to (contents of item ii of wList)
            end tell
          end repeat
        end tell
        
      end repeat
    end tell
  end tell
end tell

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy Numbers | Leave a comment

Numbers書類からPDF書き出し v2

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Numbers書類からPDF書き出し v2
— Created 2017-03-28 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set tmpPath to (path to desktop) as string
set aRes to exportNumbersDocToPDF(tmpPath)

–Pages書類からPDF書き出し
on exportNumbersDocToPDF(targFolderPath as string)
  tell application "Numbers"
    set dCount to count every document
    
if dCount = 0 then
      return false
    end if
    
set aPath to file of document 1
  end tell
  
  
set curPath to (current application’s NSString’s stringWithString:(POSIX path of aPath))’s lastPathComponent()’s stringByDeletingPathExtension()’s stringByAppendingString:".pdf"
  
set outPath to (targFolderPath & curPath)
  
  
  
tell application "Numbers"
    set anOpt to {class:export options, image quality:Best}
    
export document 1 to file outPath as PDF with properties anOpt
  end tell
end exportNumbersDocToPDF

★Click Here to Open This Script 

Posted in PDF | Tagged 10.11savvy 10.12savvy 10.13savvy Numbers | Leave a comment

RGB色をHSBAに変換して色名称を計算 v2

Posted on 2月 6, 2018 by Takaaki Naganoya

AppleScript名:RGB色をHSBAに変換して色名称を計算 v2
— Created 2018-01-08 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property NSColor : a reference to current application’s NSColor

set {rCol, gCol, bCol} to choose color
set cName to retColorDomainName(rCol, gCol, bCol, 65535) of me

on retColorDomainName(rCol as integer, gCol as integer, bCol as integer, aColorMax)
  set aCol to makeNSColorFromRGBAval(rCol, gCol, bCol, aColorMax, aColorMax) of me
  
set hueVal to aCol’s hueComponent()
  
set satVal to aCol’s saturationComponent()
  
set brightVal to aCol’s brightnessComponent()
  
  
if satVal ≤ 0.01 then set satVal to 0.0
  
  
set colName to ""
  
  
if satVal = 0.0 then
    if brightVal ≤ 0.2 then
      set colName to "black"
    else if (brightVal > 0.95) then
      set colName to "white"
    else
      set colName to "gray"
    end if
  else
    if hueVal ≤ (15.0 / 360) or hueVal ≥ (330 / 360) then
      set colName to "red"
    else if hueVal ≤ (45.0 / 360) then
      set colName to "orange"
    else if hueVal < (70.0 / 360) then
      set colName to "yellow"
    else if hueVal < (150.0 / 360) then
      set colName to "green"
    else if hueVal < (190.0 / 360) then
      set colName to "cyan"
    else if (hueVal < 250.0 / 360.0) then
      set colName to "blue"
    else if (hueVal < 290.0 / 360.0) then
      set colName to "purple"
    else
      set colName to "magenta"
    end if
  end if
  
  
return colName
end retColorDomainName

on makeNSColorFromRGBAval(redValue as integer, greenValue as integer, blueValue as integer, alphaValue as integer, aMaxVal as integer)
  set aRedCocoa to (redValue / aMaxVal) as real
  
set aGreenCocoa to (greenValue / aMaxVal) as real
  
set aBlueCocoa to (blueValue / aMaxVal) as real
  
set aAlphaCocoa to (alphaValue / aMaxVal) as real
  
set aColor to NSColor’s colorWithCalibratedRed:aRedCocoa green:aGreenCocoa blue:aBlueCocoa alpha:aAlphaCocoa
  
return aColor
end makeNSColorFromRGBAval

★Click Here to Open This Script 

Posted in Color | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

16進数文字列とNumberの相互変換 v2.2

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:16進数文字列とNumberの相互変換 v2.2
— Created 2018-01-20 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

repeat with i from 0 to 65535
  set aRes to numToHexl(i) of hexKit
  
set bRes to hextoNum(aRes) of hexKit
  
if i ≠ bRes then display dialog "Not equal to " & (i as string) & " —> " & aRes & " —> " & bRes
end repeat

script hexKit
  
  
property hexList : {missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, 10, 11, 12, 13, 14, 15}
  
  
property stringSetList : {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}
  
  
–16進数文字列からNumberに変換
  
on hextoNum(hexText as string)
    set hList to characters of hexText
    
set rhList to reverse of hList
    
set digitNum to 0
    
set sumNum to 0
    
    
repeat with i in rhList
      set j to id of contents of i
      
if j > 102 then return false
      
      
set ofN to contents of item j of hexList of me
      
if ofN = missing value then return false
      
      
set sumNum to sumNum + (16 ^ digitNum) * (ofN)
      
set digitNum to digitNum + 1
    end repeat
    
    
return sumNum as integer
  end hextoNum
  
  
  
–数値を16進数文字列に変換
  
on numToHexl(origNum)
    if origNum = 0 then return "0"
    
set resString to {}
    
repeat
      if origNum ≤ 0 then exit repeat
      
set resNum to (origNum mod 16)
      
set resText to contents of item (resNum + 1) of stringSetList
      
set resString to resText & resString
      
set origNum to origNum div 16
    end repeat
    
return (resString as string)
  end numToHexl
  
end script

★Click Here to Open This Script 

Posted in Text | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

デスクトップ上のRetina解像度のスクリーンショット画像でICNS以外のものを検索

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:デスクトップ上のRetina解像度のスクリーンショット画像でICNS以外のものを検索
— Created 2017-09-23 by Takaaki Naganoya
— Modified 2017-12-01 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use mdLib : script "Metadata Lib" version "1.0.0" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#Metadata_Lib

set theFolder to path to desktop
set fRes to mdLib’s searchFolders:{theFolder} searchString:"kMDItemResolutionHeightDPI == %@ && kMDItemResolutionWidthDPI == %@ && kMDItemIsScreenCapture == %@ && NOT (kMDItemContentTypeTree contains %@)" searchArgs:{144, 144, true, "com.apple.icns"}
–> {"/Users/me/Desktop/FromDesktop/スクリーンショット 2015-12-18 13.02.14.png", "/Users/me/Desktop/FromDesktop/スクリーンショット 2015-08-14 18.08.41.png"}

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定日時以降に作成されたファイルをSpotlight検索 v3

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定日時以降に作成されたファイルをSpotlight検索 v3
— Created 2017-09-21 by Takaaki Naganoya
— Modified 2017-09-22 by Shane Stanley
— 2017 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use mdLib : script "Metadata Lib" version "1.0.0"
–http://piyocast.com/as/archives/4841

property NSTimeZone : a reference to current application’s NSTimeZone
property NSCalendar : a reference to current application’s NSCalendar

set aDate to getDateInternationalYMDhms(2017, 10, 22, 0, 0, 0) of me
–>  (NSDate) 2017-09-21 14:02:00 +0000

set thePath to POSIX path of (path to desktop)
–>  "/Users/me/Desktop/"

set theFiles to mdLib’s searchFolders:{thePath} searchString:("kMDItemFSCreationDate >= %@") searchArgs:{aDate}
–> returns POSIX path list

on getDateInternationalYMDhms(aYear, aMonth, aDay, anHour, aMinute, aSecond)
  set theNSCalendar to NSCalendar’s currentCalendar()
  
set theDate to theNSCalendar’s dateWithEra:1 |year|:aYear |month|:aMonth |day|:aDay hour:anHour minute:aMinute |second|:aSecond nanosecond:0
  
return theDate
end getDateInternationalYMDhms

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定フォルダ内のラベル(Yellow, Red, Orange)のファイル一覧を取得

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定フォルダ内のラベル(Yellow, Red, Orange)のファイル一覧を取得
— Created 2017-12-05 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use mdLib : script "Metadata Lib" version "1.0.0" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#Metadata_Lib

set aLabelList to {5, 6, 7} –Yellow, Red, Orange
–0: No Label, 1: Gray, 2: Green, 3: Purple, 4: Blue, 5: Yellow, 6: Red, 7: Orange
set thePath to POSIX path of (path to desktop)
set aRes to spotlightFindByLabels(aLabelList, thePath) of me
–> list of POSIX path

on spotlightFindByLabels(aLabelList as list, thePath as string)
  set aList to makeRepeatinglList(length of aLabelList, "kMDItemFSLabel == %@")
  
set aStr to retStrFromArrayWithDelimiter(aList, " OR ") of me
  
set fRes to mdLib’s searchFolders:{thePath} searchString:aStr searchArgs:aLabelList
  
return fRes
end spotlightFindByLabels

–リストを指定デリミタをはさんでテキスト化
on retStrFromArrayWithDelimiter(aList as list, aDelim as string)
  set anArray to current application’s NSArray’s arrayWithArray:aList
  
return (anArray’s componentsJoinedByString:aDelim) as string
end retStrFromArrayWithDelimiter

–指定回数、指定アイテムを連結したリストを作成
on makeRepeatinglList(hitNum as integer, hitItem as string)
  set outList to {}
  
repeat hitNum times
    set the end of outList to hitItem
  end repeat
  
return outList
end makeRepeatinglList

★Click Here to Open This Script 

Posted in file Spotlight | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Post navigation

  • Older posts
  • Newer posts

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

Google Search

Popular posts

  • 開発機としてM2 Mac miniが来たのでガチレビュー
  • macOS 15, Sequoia
  • Pages本執筆中に、2つの書類モード切り替えに気がついた
  • Numbersで選択範囲のセルの前後の空白を削除
  • メキシカンハットの描画
  • Pixelmator Pro v3.6.4でAppleScriptからの操作時の挙動に違和感が
  • AppleScriptによる並列処理
  • Safariで「プロファイル」機能を使うとAppleScriptの処理に影響
  • macOS 15でも変化したText to Speech環境
  • AppleScript入門③AppleScriptを使った「自動化」とは?
  • デフォルトインストールされたフォント名を取得するAppleScript
  • macOS 15 リモートApple Eventsにバグ?
  • 【続報】macOS 15.5で特定ファイル名パターンのfileをaliasにcastすると100%クラッシュするバグ
  • AppleScript入門① AppleScriptってなんだろう?
  • Script Debuggerの開発と販売が2025年に終了
  • macOS 14で変更になったOSバージョン取得APIの返り値
  • NSObjectのクラス名を取得 v2.1
  • 有害ではなくなっていたSpaces
  • macOS 15:スクリプトエディタのAppleScript用語辞書を確認できない
  • Xcode上のAppleScriptObjCのプログラムから、Xcodeのログ欄へのメッセージ出力を実行

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1391) 10.14savvy (587) 10.15savvy (438) 11.0savvy (283) 12.0savvy (212) 13.0savvy (194) 14.0savvy (147) 15.0savvy (135) CotEditor (66) Finder (51) iTunes (19) Keynote (119) 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 (76) Pages (55) 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
  • 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
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 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