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

指定PDFの全ページからリンクアノテーションのURLを取得(http)v2

Posted on 2月 14, 2018 by Takaaki Naganoya

指定のPDFの全ページを走査してリンクアノテーションのURLのうちURL Schemeが”http”のものを抽出し、”http://piyocast.com/as/archives/” を含むURLを取得するAppleScriptです。

macOS 10.13以降でも動作するようにしてあります。電子書籍のPDFから本Blogへのリンクを張ってある箇所を検出するために作成したものです。

AppleScript名:指定PDFの全ページからリンクアノテーションのURLを取得(http)v2
— Created 2017-06-08 by Takaaki Naganoya
— Modified 2018-02-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "Quartz"

property |NSURL| : a reference to current application’s |NSURL|
property PDFDocument : a reference to current application’s PDFDocument

set aPOSIX to POSIX path of (choose file of type {"com.adobe.pdf"} with prompt "Choose a PDF with Annotation")
set linkList to getLinkURLFromPDF(aPOSIX, "http", "http://piyocast.com/as/archives/") of me
–>  {​​​​​{​​​​​​​pageNum:39, ​​​​​​​linkURL:"http://piyocast.com/as/archives/69"​​​​​},….}

on getLinkURLFromPDF(aPOSIX, urlScheme, condURL)
  set v2 to system attribute "sys2" –> macOS 10.12 =12
  
  
set aURL to (|NSURL|’s fileURLWithPath:aPOSIX)
  
  
set aPDFdoc to PDFDocument’s alloc()’s initWithURL:aURL
  
set pCount to aPDFdoc’s pageCount()
  
  
set outList to {}
  
  
–PDFのページでループ
  
repeat with ii from 0 to (pCount – 1)
    set tmpPage to (aPDFdoc’s pageAtIndex:ii)
    
    
set anoList to (tmpPage’s annotations()) as list
    
if anoList is not equal to {missing value} then –指定PDF中にAnotationが存在した
      
      
–対象PDFPage内で検出されたAnnotationでループ
      
repeat with i in anoList
        
        
if v2 < 13 then
          –to macOS Sierra
          
set aType to (i’s type()) as string
        else
          –macOS High Sierra or later
          
set aType to (i’s |Type|()) as string
        end if
        
        
—
        
if aType = "Link" then
          set tmpURL to i’s |URL|()
          
if tmpURL is not equal to missing value then
            set tmpScheme to (tmpURL’s |scheme|()) as string
            
if tmpScheme = urlScheme then
              set urlStr to (tmpURL’s absoluteString()) as string
              
              
if (urlStr contains condURL) then
                set the end of outList to {pageNum:(ii + 1), linkURL:urlStr}
              end if
              
            end if
          end if
        end if
      end repeat
    end if
  end repeat
  
  
return outList
end getLinkURLFromPDF

★Click Here to Open This Script 

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

指定PDFの全ページからリンクアノテーションのURLを取得(applescript) v2

Posted on 2月 14, 2018 by Takaaki Naganoya

指定のPDFの全ページを走査してリンクアノテーションのURLのうちURL Schemeが”applescript”のものを抽出して、Link Scriptの内容を取得するAppleScriptです。

macOS 10.13以降でも動作するようにしてあります。

AppleScript名:指定PDFの全ページからリンクアノテーションのURLを取得(applescript) v2
— Created 2017-06-08 by Takaaki Naganoya
— Modified 2018-02-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "Quartz"

property |NSURL| : a reference to current application’s |NSURL|
property NSString : a reference to current application’s NSString
property PDFDocument : a reference to current application’s PDFDocument
property NSMutableDictionary : a reference to current application’s NSMutableDictionary
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding

set aPOSIX to POSIX path of (choose file of type {"com.adobe.pdf"} with prompt "Choose a PDF with Annotation")
set linkList to getLinkURLFromPDF(aPOSIX, "applescript") of me
–>  {​​​​​{​​​​​​​pageNum:95, ​​​​​​​linkScript:"set aStr to \"ぴよまるソフトウェア\" set aPath to choose file name……}}

on getLinkURLFromPDF(aPOSIX, urlScheme)
  set v2 to system attribute "sys2" –> macOS 10.12 =12
  
  
set aURL to (|NSURL|’s fileURLWithPath:aPOSIX)
  
  
set aPDFdoc to PDFDocument’s alloc()’s initWithURL:aURL
  
set pCount to aPDFdoc’s pageCount()
  
  
set outList to {}
  
  
–PDFのページでループ
  
repeat with ii from 0 to (pCount – 1)
    set tmpPage to (aPDFdoc’s pageAtIndex:ii)
    
    
set anoList to (tmpPage’s annotations()) as list
    
if anoList is not equal to {missing value} then –指定PDF中にAnotationが存在した
      
      
–対象PDFPage内で検出されたAnnotationでループ
      
repeat with i in anoList
        
        
if v2 < 13 then
          –to macOS Sierra
          
set aType to (i’s type()) as string
        else
          –macOS High Sierra or later
          
set aType to (i’s |Type|()) as string
        end if
        
        
—
        
if aType = "Link" then
          set tmpURL to i’s |URL|()
          
if tmpURL is not equal to missing value then
            set tmpScheme to (tmpURL’s |scheme|()) as string
            
            
if tmpScheme = urlScheme then
              set urlStr to (tmpURL’s absoluteString()) as string
              
set urlRec to parseQueryDictFromURLString(urlStr) of me
              
set tmpScript to (urlRec’s |script|) as string
              
              
set the end of outList to {pageNum:(ii + 1), linkScript:tmpScript}
              
            end if
          end if
        end if
      end repeat
    end if
  end repeat
  
  
return outList
end getLinkURLFromPDF

on parseQueryDictFromURLString(aURLStr as string)
  if aURLStr = "" then error "No URL String"
  
  
set aURL to |NSURL|’s URLWithString:aURLStr
  
set aQuery to aURL’s query() –Get Query string part from URL
  
if aQuery’s |length|() = 0 then return false
  
  
set aDict to NSMutableDictionary’s alloc()’s init()
  
set aParamList to (aQuery’s componentsSeparatedByString:"&") as list
  
  
repeat with i in aParamList
    set j to contents of i
    
if length of j > 0 then
      set tmpStr to (NSString’s stringWithString:j)
      
set eList to (tmpStr’s componentsSeparatedByString:"=")
      
set anElement to (eList’s firstObject()’s stringByReplacingPercentEscapesUsingEncoding:(NSUTF8StringEncoding))
      
set aValStr to (eList’s lastObject()’s stringByReplacingPercentEscapesUsingEncoding:(NSUTF8StringEncoding))
      (
aDict’s setObject:aValStr forKey:anElement)
    end if
  end repeat
  
  
return aDict
end parseQueryDictFromURLString

★Click Here to Open This Script 

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

画像の指定エリアを塗りつぶし

Posted on 2月 14, 2018 by Takaaki Naganoya


▲Before


▲After

AppleScript名:画像の指定エリアを塗りつぶし
— Created 2017-11-19 by Takaaki Naganoya
— Modified 2018-02-14 by Takaaki Naganoya
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property NSUUID : a reference to current application’s NSUUID
property NSColor : a reference to current application’s NSColor
property NSString : a reference to current application’s NSString
property NSImage : a reference to current application’s NSImage
property NSScreen : a reference to current application’s NSScreen
property NSBezierPath : a reference to current application’s NSBezierPath
property NSPNGFileType : a reference to current application’s NSPNGFileType
property NSBitmapImageRep : a reference to current application’s NSBitmapImageRep

–塗りつぶしエリア(複数)
set drawList to {{origin:{x:0, y:0}, |size|:{width:200, height:100}}, {origin:{x:300, y:100}, |size|:{width:50, height:50}}}

set imgPath to POSIX path of (choose file of type {"public.image"})
set anImage to NSImage’s alloc()’s initWithContentsOfFile:imgPath

set fillColor to (NSColor’s colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.9)

–塗りつぶし処理呼び出し
set resImage to drawImageWithColorFill(anImage, drawList, fillColor) of me

set aUUIDstr to (NSUUID’s UUID()’s UUIDString()) as string
set aPath to ((NSString’s stringWithString:imgPath)’s stringByDeletingLastPathComponent()’s stringByAppendingPathComponent:aUUIDstr)’s stringByAppendingPathExtension:"png"

set fRes to saveImageRepAtPathAsPNG(resImage, aPath) of me

on drawImageWithColorFill(anImage, drawList, fillColor)
  set retinaF to (NSScreen’s mainScreen()’s backingScaleFactor()) as real
  
–>  2.0 (Retina) / 1.0 (Non Retina)
  
  
anImage’s lockFocus() –描画開始
  
  
repeat with i in drawList
    set origX to (x of origin of i) / retinaF
    
set origY to (y of origin of i) / retinaF
    
set sizeX to (width of |size| of i) / retinaF
    
set sizeY to (height of |size| of i) / retinaF
    
    
set theRect to {{x:origX, y:origY}, {width:sizeX, height:sizeY}}
    
    
set theNSBezierPath to NSBezierPath’s bezierPath
    (
theNSBezierPath’s appendBezierPathWithRect:theRect)
    
    
fillColor’s |set|() –色設定
    
theNSBezierPath’s fill() –ぬりつぶし
  end repeat
  
  
anImage’s unlockFocus() –描画ここまで
  
  
return anImage –returns NSImage
end drawImageWithColorFill

–画像を指定パスにPNG形式で保存
on saveImageRepAtPathAsPNG(anImage, outPath)
  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:(NSPNGFileType) |properties|:(missing value))
  
return (myNewImageData’s writeToFile:newPath atomically:true) as boolean
end saveImageRepAtPathAsPNG

★Click Here to Open This Script 

Posted in file Image | Tagged 10.11savvy 10.12savvy 10.13savvy | 1 Comment

表示中のCotEditor書類の「前」のファイルを縦書きでオープン v2

Posted on 2月 14, 2018 by Takaaki Naganoya

CotEditorでオープン中の書類の「前」のファイルを縦書きでオープンするAppleScriptです。

CotEditorでオープン中の書類のパスを取得して、同一フォルダ内にあるファイル名一覧からオープン中の書類の「前」に該当する書類をオープンします。

ファイルオープン後にCotEditorのメニューをGUI Scriptingで強制的に操作して縦書きに設定します。

CotEditor v3.3.2のメニューにバグがあって、横書きのメニュー項目にも縦書きのメニュー項目にも「縦書き」と書いてあり、メニュー項目を名称で指定するとうまく動きません。そこだけItem No.で指定しています。このメニュー項目の不具合については、近い将来のアップデートで修正される見込みです。


▲CotEditor内蔵のScript Menuから実行するとGUI Scriptingの実行が制限されて縦書きにならない


▲OS側のScript Menuから実行すると問題なく実行できる

AppleScript名:表示中のCotEditor書類の「前」のファイルを縦書きでオープン v2
— Created 2017-12-15 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use bPlus : script "BridgePlus"

property |NSURL| : a reference to current application’s |NSURL|
property NSArray : a reference to current application’s NSArray
property NSString : a reference to current application’s NSString
property SMSForder : a reference to current application’s SMSForder
property NSPredicate : a reference to current application’s NSPredicate
property NSFileManager : a reference to current application’s NSFileManager
property NSMutableArray : a reference to current application’s NSMutableArray
property NSSortDescriptor : a reference to current application’s NSSortDescriptor
property NSURLIsPackageKey : a reference to current application’s NSURLIsPackageKey
property NSURLIsDirectoryKey : a reference to current application’s NSURLIsDirectoryKey
property NSDirectoryEnumerationSkipsHiddenFiles : a reference to current application’s NSDirectoryEnumerationSkipsHiddenFiles
property NSDirectoryEnumerationSkipsPackageDescendants : a reference to current application’s NSDirectoryEnumerationSkipsPackageDescendants
property NSDirectoryEnumerationSkipsSubdirectoryDescendants : a reference to current application’s NSDirectoryEnumerationSkipsSubdirectoryDescendants

load framework

tell application "CotEditor"
  set dCount to count every document
  
if dCount = 0 then return
  
  
tell front document
    set curPath to path
  end tell
  
  
tell window 1
    set aBounds to bounds
  end tell
end tell

set aPath to NSString’s stringWithString:curPath
set fileName to (aPath’s lastPathComponent()) –ファイル名
set pathExtension to aPath’s pathExtension() as string
set parentFol to (aPath’s stringByDeletingLastPathComponent()) as string —親フォルダ

–同じフォルダから同じ拡張子のファイルのファイル名を取得
set fList to my getFilesByIncludedStringInName:(pathExtension) fromDirectory:(parentFol) exceptPackages:(true)

–昇順ソート
set aArray to NSArray’s arrayWithArray:fList
set desc1 to NSSortDescriptor’s sortDescriptorWithKey:"self" ascending:true selector:"localizedCaseInsensitiveCompare:"
set bArray to aArray’s sortedArrayUsingDescriptors:{desc1}

–ファイル名検索
–set aIndex to bArray’s indexOfObjectIdenticalTo:fileName
set aIndex to (SMSForder’s indexesOfItem:fileName inArray:bArray inverting:false) as list
if aIndex = {} then
  display notification "Error: File Not Found"
  
return
end if

set bIndex to (contents of first item of aIndex) + 1 – 1 –0 based to 1 based conversion & previous one
set aLen to length of (bArray as list)
if bIndex > aLen then
  display notification "Error: Out of bounds"
  
return
end if

set newFile to contents of item bIndex of (bArray as list)
set newPath to parentFol & "/" & newFile

tell application "CotEditor"
  set oldDoc to front document
  
  
open (POSIX file newPath) as alias
  
tell window 1
    set bounds to aBounds
  end tell
  
  
close oldDoc without saving
end tell

makeWinVertical() of me –縦書き表示

–指定フォルダ内の指定文字列を含むファイル名のファイルをPOSIX pathのlistで抽出する
on getFilesByIncludedStringInName:(fileNameStr as string) fromDirectory:(sourceFolder) exceptPackages:(packageF as boolean)
  set fileManager to NSFileManager’s defaultManager()
  
set aURL to |NSURL|’s fileURLWithPath:sourceFolder
  
set theOptions to ((NSDirectoryEnumerationSkipsPackageDescendants) as integer) + ((NSDirectoryEnumerationSkipsHiddenFiles) as integer) + ((NSDirectoryEnumerationSkipsSubdirectoryDescendants) as integer)
  
set directoryContents to fileManager’s contentsOfDirectoryAtURL:aURL includingPropertiesForKeys:{} options:theOptions |error|:(missing value)
  
set findPredicates to NSPredicate’s predicateWithFormat_("lastPathComponent CONTAINS %@", fileNameStr)
  
set foundItemList to directoryContents’s filteredArrayUsingPredicate:findPredicates
  
  
–Remove Folders From found URL Array
  
set anArray to NSMutableArray’s alloc()’s init()
  
repeat with i in foundItemList
    set j to contents of i
    
set {theResult, isDirectory} to (j’s getResourceValue:(reference) forKey:(NSURLIsDirectoryKey) |error|:(missing value))
    
    
–Collect files
    
if (isDirectory as boolean = false) then
      (anArray’s addObject:j)
      
    else if (packageF = false) then
      –Allow Package files?
      
set {theResult, isPackage} to (j’s getResourceValue:(reference) forKey:(NSURLIsPackageKey) |error|:(missing value))
      
if (isPackage as boolean) = true then
        (anArray’s addObject:j)
      end if
    end if
    
  end repeat
  
  
return (anArray’s valueForKey:"lastPathComponent") as list
end getFilesByIncludedStringInName:fromDirectory:exceptPackages:

–Make CotEditor’s front window to Vertical display mode (Tategaki)
on makeWinVertical()
  activate application "CotEditor"
  
tell application "System Events"
    tell process "CotEditor"
      try
        click menu item 3 of menu 1 of menu item "文章の方向" of menu 1 of menu bar item "フォーマット" of menu bar 1
      end try
    end tell
  end tell
end makeWinVertical

★Click Here to Open This Script 

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

表示中のCotEditor書類の「次」のファイルを縦書きでオープン v2

Posted on 2月 14, 2018 by Takaaki Naganoya

CotEditorでオープン中の書類の「次」のファイルを縦書きでオープンするAppleScriptです。

CotEditorでオープン中の書類のパスを取得して、同一フォルダ内にあるファイル名一覧からオープン中の書類の「次」に該当する書類をオープンします。

ファイルオープン後にCotEditorのメニューをGUI Scriptingで強制的に操作して縦書きに設定します。

CotEditor v3.3.2のメニューにバグがあって、横書きのメニュー項目にも縦書きのメニュー項目にも「縦書き」と書いてあり、メニュー項目を名称で指定するとうまく動きません。そこだけItem No.で指定しています。このメニュー項目の不具合については、近い将来のアップデートで修正される見込みです。


▲CotEditor内蔵のScript Menuから実行するとGUI Scriptingの実行が制限されて縦書きにならない


▲OS側のScript Menuから実行すると問題なく実行できる

AppleScript名:表示中のCotEditor書類の「次」のファイルを縦書きでオープン v2
— Created 2017-12-15 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use bPlus : script "BridgePlus"

property |NSURL| : a reference to current application’s |NSURL|
property NSArray : a reference to current application’s NSArray
property NSString : a reference to current application’s NSString
property SMSForder : a reference to current application’s SMSForder
property NSPredicate : a reference to current application’s NSPredicate
property NSFileManager : a reference to current application’s NSFileManager
property NSMutableArray : a reference to current application’s NSMutableArray
property NSSortDescriptor : a reference to current application’s NSSortDescriptor
property NSURLIsPackageKey : a reference to current application’s NSURLIsPackageKey
property NSURLIsDirectoryKey : a reference to current application’s NSURLIsDirectoryKey
property NSDirectoryEnumerationSkipsHiddenFiles : a reference to current application’s NSDirectoryEnumerationSkipsHiddenFiles
property NSDirectoryEnumerationSkipsPackageDescendants : a reference to current application’s NSDirectoryEnumerationSkipsPackageDescendants
property NSDirectoryEnumerationSkipsSubdirectoryDescendants : a reference to current application’s NSDirectoryEnumerationSkipsSubdirectoryDescendants

load framework

tell application "CotEditor"
  set dCount to count every document
  
if dCount = 0 then return
  
  
tell front document
    set curPath to path
  end tell
  
  
tell window 1
    set aBounds to bounds
  end tell
end tell

set aPath to NSString’s stringWithString:curPath
set fileName to (aPath’s lastPathComponent()) –ファイル名
set pathExtension to aPath’s pathExtension() as string
set parentFol to (aPath’s stringByDeletingLastPathComponent()) as string —親フォルダ

–同じフォルダから同じ拡張子のファイルのファイル名を取得
set fList to my getFilesByIncludedStringInName:(pathExtension) fromDirectory:(parentFol) exceptPackages:(true)

–昇順ソート
set aArray to NSArray’s arrayWithArray:fList
set desc1 to NSSortDescriptor’s sortDescriptorWithKey:"self" ascending:true selector:"localizedCaseInsensitiveCompare:"
set bArray to aArray’s sortedArrayUsingDescriptors:{desc1}

–ファイル名検索
set aIndex to (SMSForder’s indexesOfItem:fileName inArray:bArray inverting:false) as list
if aIndex = {} then
  display notification "Error: File Not Found"
  
return
end if

set bIndex to (contents of first item of aIndex) + 1 + 1 –0 based to 1 based conversion & next one
set aLen to length of (bArray as list)
if bIndex > aLen then
  display notification "Error: Out of bounds"
  
return
end if

set newFile to contents of item bIndex of (bArray as list)
set newPath to parentFol & "/" & newFile

tell application "CotEditor"
  set oldDoc to front document
  
  
open (POSIX file newPath) as alias
  
tell window 1
    set bounds to aBounds
  end tell
  
  
close oldDoc without saving
end tell

makeWinVertical() of me –縦書き表示

–指定フォルダ内の指定文字列を含むファイル名のlistを抽出する
on getFilesByIncludedStringInName:(fileNameStr as string) fromDirectory:(sourceFolder) exceptPackages:(packageF as boolean)
  set fileManager to NSFileManager’s defaultManager()
  
set aURL to |NSURL|’s fileURLWithPath:sourceFolder
  
set theOptions to (NSDirectoryEnumerationSkipsPackageDescendants as integer) + (NSDirectoryEnumerationSkipsHiddenFiles as integer) + (NSDirectoryEnumerationSkipsSubdirectoryDescendants as integer)
  
set directoryContents to fileManager’s contentsOfDirectoryAtURL:aURL includingPropertiesForKeys:{} options:theOptions |error|:(missing value)
  
set findPredicates to NSPredicate’s predicateWithFormat_("lastPathComponent CONTAINS %@", fileNameStr)
  
set foundItemList to directoryContents’s filteredArrayUsingPredicate:findPredicates
  
  
–Remove Folders From found URL Array
  
set anArray to NSMutableArray’s alloc()’s init()
  
repeat with i in foundItemList
    set j to contents of i
    
set {theResult, isDirectory} to (j’s getResourceValue:(reference) forKey:(NSURLIsDirectoryKey) |error|:(missing value))
    
    
–Collect files
    
if (isDirectory as boolean = false) then
      (anArray’s addObject:j)
    else if (packageF = false) then
      –Allow Package files?
      
set {theResult, isPackage} to (j’s getResourceValue:(reference) forKey:(NSURLIsPackageKey) |error|:(missing value))
      
if (isPackage as boolean) = true then
        (anArray’s addObject:j)
      end if
    end if
    
  end repeat
  
  
return (anArray’s valueForKey:"lastPathComponent") as list
end getFilesByIncludedStringInName:fromDirectory:exceptPackages:

–Make CotEditor’s front window to Vertical display mode (Tategaki)
on makeWinVertical()
  activate application "CotEditor"
  
tell application "System Events"
    tell process "CotEditor"
      try
        click menu item 3 of menu 1 of menu item "文章の方向" of menu 1 of menu bar item "フォーマット" of menu bar 1
      end try
    end tell
  end tell
end makeWinVertical

★Click Here to Open This Script 

Posted in file GUI Scripting | Tagged 10.11savvy 10.12savvy 10.13savvy CotEditor | Leave a comment

AirServerで出力先名を宣言する

Posted on 2月 13, 2018 by Takaaki Naganoya

AppleScript名:AirServerで出力先名を宣言する
tell application "AirServer"
  start broadcast as "Piyomaru MacBook Pro"
end tell

★Click Here to Open This Script 

Posted in AirPlay Network | Tagged 10.11savvy 10.12savvy 10.13savvy AirServer | Leave a comment

AirServer出力を停止する

Posted on 2月 13, 2018 by Takaaki Naganoya

AppleScript名:AirServer出力を停止する
tell application "AirServer"
  stop broadcast
end tell

★Click Here to Open This Script 

Posted in AirPlay Network | Tagged 10.11savvy 10.12savvy 10.13savvy AirServer | Leave a comment

指定フォルダ以下のテキストファイルのファイル名冒頭についている数字から欠番を求める

Posted on 2月 13, 2018 by Takaaki Naganoya
AppleScript名:指定フォルダ以下のテキストファイルのファイル名冒頭についている数字から欠番を求める
— Created 2017-09-04 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
use mdLib : script "Metadata Lib" version "1.0.0" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#Metadata_Lib
use bPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

property NSString : a reference to current application’s NSString
property SMSForder : a reference to current application’s SMSForder
property NSIndexSet : a reference to current application’s NSIndexSet
property NSMutableSet : a reference to current application’s NSMutableSet
property NSMutableArray : a reference to current application’s NSMutableArray
property NSRegularExpression : a reference to current application’s NSRegularExpression
property NSRegularExpressionAnchorsMatchLines : a reference to current application’s NSRegularExpressionAnchorsMatchLines
property NSRegularExpressionDotMatchesLineSeparators : a reference to current application’s NSRegularExpressionDotMatchesLineSeparators

load framework –BridgePlus’s force framework loading command

–選択したフォルダ以下のPlain TextをすべてSpotlightで求める(POSIX path list)
set theFolder to (choose folder)

set a1Dat to current application’s NSDate’s timeIntervalSinceReferenceDate()
set aRes to retMissingNumberFromEachFiles(theFolder, {"public.plain-text"}) of me
–>  {}
set b1Dat to current application’s NSDate’s timeIntervalSinceReferenceDate()
set c1Dat to b1Dat – a1Dat

on retMissingNumberFromEachFiles(theFolder, fileTypeList)
  set theFiles to mdLib’s searchFolders:{theFolder} searchString:"kMDItemContentType IN[c] %@" searchArgs:fileTypeList
  
if theFiles = {} then return
  
  
–取得したPOSIX Pathのリストからファイル名の部分のみ抽出
  
set anArray to NSMutableArray’s arrayWithArray:theFiles
  
set bArray to (anArray’s valueForKeyPath:"lastPathComponent") as list
  
  
–各ファイルの名称の冒頭から1~3桁 の数字を取り出して、全角–>半角変換を行いつつリストに追加
  
set nArray to NSMutableArray’s new()
  
repeat with i in bArray
    set j to contents of i
    
set aRes to (my findPattern:"^\\d{1,3}" inString:j)
    
if aRes is not equal to {} then
      set jj to (contents of first item of aRes) as string
      
set jj2 to (SMSForder’s transformedFrom:jj ICUTransform:"Fullwidth-Halfwidth" inverse:false) as integer
      (
nArray’s addObject:jj2)
    end if
  end repeat
  
  
–最大値、最小値をもとに連番リストを作成し、ファイル名から得られた配列データとの補集合を求める
  
set maxRes to (nArray’s valueForKeyPath:"@max.self")’s intValue()
  
set minRes to (nArray’s valueForKeyPath:"@min.self")’s intValue()
  
  
–最小値から最大値までの連番リスト作成
  
set theIndexSet to NSIndexSet’s indexSetWithIndexesInRange:{minRes, maxRes}
  
set theList to (SMSForder’s arrayWithIndexSet:theIndexSet) as list
  
  
set aSet to NSMutableSet’s setWithArray:theList
  
set bSet to NSMutableSet’s setWithArray:nArray
  
aSet’s minusSet:bSet –補集合
  
  
return (aSet’s allObjects() as list)
  
end retMissingNumberFromEachFiles

on findPattern:thePattern inString:theString
  set theOptions to ((NSRegularExpressionDotMatchesLineSeparators) as integer) + ((NSRegularExpressionAnchorsMatchLines) as integer)
  
set theRegEx to NSRegularExpression’s regularExpressionWithPattern:thePattern options:theOptions |error|:(missing value)
  
set theFinds to theRegEx’s matchesInString:theString options:0 range:{location:0, |length|:length of theString}
  
set theFinds to theFinds as list
  
set theResult to {}
  
set theNSString to NSString’s stringWithString:theString
  
  
repeat with i in theFinds
    set theRange to (contents of i)’s range()
    
set end of theResult to (theNSString’s substringWithRange:theRange) as string
  end repeat
  
return theResult
end findPattern:inString:

★Click Here to Open This Script 

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

指定フォルダ以下の指定形式の書類をすべてもとめて拡張子をはずしたファ

Posted on 2月 13, 2018 by Takaaki Naganoya
AppleScript名:指定フォルダ以下の指定形式の書類をすべてもとめて拡張子をはずしたファイル名に重複がないかチェック v2
— Created 2017-10-28 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 docUTIList to {"net.daringfireball.markdown", "com.apple.iwork.pages.sffpages"}
set origFol to (choose folder)
set dRes to detectDocNameDuplicateWithoutExt(origFol, docUTIList) of me
–> true / false

–origFolはaliasでもPOSIX pathでも可
on detectDocNameDuplicateWithoutExt(origFol, docTypeList as list)
  script spdMD
    property allResList : {}
  end script
  
  
set (allResList of spdMD) to {}
  
  
repeat with i in docTypeList
    set j to contents of i
    
set aResList to (mdLib’s searchFolders:{origFol} searchString:("kMDItemContentTypeTree CONTAINS %@") searchArgs:{j})
    
if aResList = missing value or aResList = {} then
      –Hitしなかった
    else
      set (allResList of spdMD) to (allResList of spdMD) & aResList
    end if
  end repeat
  
  
set aLen to length of contents of (allResList of spdMD)
  
if aLen = 0 then error "No match"
  
  
set anArray to current application’s NSArray’s arrayWithArray:(allResList of spdMD)
  
set aRes to anArray’s valueForKeyPath:"lastPathComponent.stringByDeletingPathExtension"
  
set b1Res to uniquify1DList(aRes as list, true) of me
  
set b1Len to length of b1Res
  
  
if aLen = b1Len then
    return true — No Duplicates
  else
    return false –Some duplicates
  end if
end detectDocNameDuplicateWithoutExt

–1D/2D Listをユニーク化
on uniquify1DList(theList as list, aBool as boolean)
  set aArray to current application’s NSArray’s arrayWithArray:theList
  
set bArray to aArray’s valueForKeyPath:"@distinctUnionOfObjects.self"
  
return bArray as list
end uniquify1DList

★Click Here to Open This Script 

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

指定フォルダ以下の指定形式の書類をすべてもとめてファイル名に重複がないかチェック

Posted on 2月 13, 2018 by Takaaki Naganoya
AppleScript名:指定フォルダ以下の指定形式の書類をすべてもとめてファイル名に重複がないかチェック
— Created 2017-10-28 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"

set origFol to POSIX path of (choose folder)

set aResList to mdLib’s searchFolders:{origFol} searchString:("kMDItemContentTypeTree CONTAINS %@ || kMDItemContentTypeTree CONTAINS %@") searchArgs:{"net.daringfireball.markdown", "com.apple.iwork.pages.sffpages"}
if aResList = missing value or aResList = {} then
  return false
end if

set anArray to current application’s NSArray’s arrayWithArray:aResList
set aRes to anArray’s valueForKeyPath:"lastPathComponent"

set bLen to length of (aRes as list)

set b1Res to uniquify1DList(aRes as list, true) of me
set b1Len to length of b1Res

if bLen = b1Len then
  display dialog "No Duplicates"
else
  display dialog "Some Duplicates"
end if

on getSameItemsInLists(aList as list, bList as list)
  
  –ASオブジェクトをCocoaオブジェクトに変換
  
set aArray to current application’s NSArray’s arrayWithArray:aList
  
set bArray to current application’s NSArray’s arrayWithArray:bList
  
  — まとめる
  
set allSet to current application’s NSMutableSet’s setWithArray:aArray
  
allSet’s addObjectsFromArray:bArray
  
  –重複する要素のみ抜き出す
  
set duplicateSet to current application’s NSMutableSet’s setWithArray:aArray
  
duplicateSet’s intersectSet:(current application’s NSSet’s setWithArray:bArray)
  
  –重複部分だけを返す
  
set resArray to duplicateSet’s allObjects()
  
  set resList to resArray as list
  
  return resList
  
end getSameItemsInLists

–1D/2D Listをユニーク化
on uniquify1DList(theList as list, aBool as boolean)
  set aArray to current application’s NSArray’s arrayWithArray:theList
  
set bArray to aArray’s valueForKeyPath:"@distinctUnionOfObjects.self"
  
return bArray as list
end uniquify1DList

★Click Here to Open This Script 

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

指定ファイルのUTIを取得

Posted on 2月 13, 2018 by Takaaki Naganoya
AppleScript名:Vanilla Scriptで指定ファイルのUTIを求める
set aFile to choose file

tell application "System Events"
  set aUTI to type identifier of aFile
  
return aUTI
end tell

★Click Here to Open This Script 

AppleScript名:指定ファイルのUTIを取得
— Created 2016-10-24 by Takaaki Naganoya
— Modified 2016-10-25 by Shane Stanley
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use BridgePlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

set aFile to POSIX path of (choose file)
set aUTI to retFileFormatUTIFromPath(aFile) of me

on retFileFormatUTIFromPath(aPOSIXpath as string)
  load framework
  
set aPath to current application’s NSString’s stringWithString:aPOSIXpath
  
set aExt to (aPath’s pathExtension()) as string
  
return (current application’s SMSForder’s UTIForExtension:aExt) as list of string or string –as anything
end retFileFormatUTIFromPath

★Click Here to Open This Script 

AppleScript名:指定ファイルのUTIを取得 v2.scptd
use AppleScript version "2.5" — El Capitan (10.11) or later
use framework "Foundation"
use scripting additions

property |NSURL| : a reference to current application’s |NSURL|
property NSURLTypeIdentifierKey : a reference to current application’s NSURLTypeIdentifierKey

set aPath to POSIX path of (choose file)
set utiRes to retUTIfromPath(aPath) of me

on retUTIfromPath(aPOSIXPath)
  set aURL to |NSURL|’s fileURLWithPath:aPOSIXPath
  
set {theResult, theValue} to aURL’s getResourceValue:(reference) forKey:NSURLTypeIdentifierKey |error|:(missing value)
  
  
if theResult = true then
    return theValue as string
  else
    return theResult
  end if
end retUTIfromPath

★Click Here to Open This Script 

Posted in file System URL UTI | Tagged 10.11savvy 10.12savvy 10.13savvy NSURL NSURLTypeIdentifierKey | Leave a comment

GHKitのじっけん

Posted on 2月 13, 2018 by Takaaki Naganoya

–> GHKit.framework

AppleScript名:GHKitのじっけん
— Created 2016-04-12 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "GHKit" –https://github.com/gabriel/GHKit
–AppleScriptObjC uses "_" as special character (equivalent to ":" in method names). So, I changed them in whole project.
–  Original Method Name: gh_parseISO8601:
–  Converted Method Name: GHparseISO8601:

set aStr to current application’s NSString’s stringWithString:"Sun, 06 Nov 1994 08:49:37 +0000"
set aDate to (current application’s NSDate’s GHparseRFC822:aStr) as date
–>  date "1994年11月6日日曜日 17:49:37"

set bStr to current application’s NSString’s stringWithString:"1997-07-16T19:20:30.045Z"
set bDate to (current application’s NSDate’s GHparseISO8601:bStr) as date
–>  date "1997年7月17日木曜日 4:20:30"

set cDateStr to bDate’s GHformatHTTP()
–>  (NSString) "Wed, 16 Jul 1997 19:20:30 GMT"

set dDate to current application’s NSDate’s GHparseTimeSinceEpoch:(1.23456789E+9)
–>  (NSDate) 2009-02-13 23:31:30 +0000

set eDate to current application’s NSDate’s |date|()
eDate’s GHisToday() as boolean
–>  true
—–GHyesterday() cause error..

set fDate to eDate’s GHaddDays:-1
fDate’s GHwasYesterday() as boolean
–>  true

set ffRes to ((fDate’s GHtimeAgo:false)’s |description|()) as string
–> "1 day"

set anArray to current application’s NSArray’s arrayWithArray:{1, 1, 3}
set cArray to anArray’s GHuniq() as list
–>   {​​​​​1, ​​​​​3​​​}

set aDic to current application’s NSDictionary’s dictionaryWithDictionary:{key1:2, key2:3.1, key3:true}
set aJSONstr to (aDic’s GHtoJSON:(current application’s NSJSONWritingPrettyPrinted) |error|:(missing value)) as string
(*
–> (NSString) "{\n "key1" : 2,\n "key3" : true,\n "key2" : 3.1\n}"
*)

(current application’s NSString’s GHisBlank:" ") as boolean
–>  true

(current application’s NSString’s GHisBlank:(missing value)) as boolean
–>  true

set aStr to current application’s NSString’s stringWithString:" some text "
set a1Str to (aStr’s GHstrip()) as string
–> "some text"

set a2Str to (aStr’s GHpresent()) as string
–> " some text "

set a3Str to aStr’s GHreverse()
–>   " txet emos "

set a4Str to aStr’s GHcount:"e"
–> 2

★Click Here to Open This Script 

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

Absolute Timeを取得

Posted on 2月 13, 2018 by Takaaki Naganoya
AppleScript名:Absolute Timeを取得
— Created 2016-07-12 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

–タイムスタンプ取得(Jan 1 2001 00:00:00 GMTからの相対秒、Absolute Timeで取得)
set aTime to current application’s NSString’s stringWithFormat_("%@", current application’s CFAbsoluteTimeGetCurrent()) as string
–>  "490022703.57607"

★Click Here to Open This Script 

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

自然言語テキストから日付を抽出

Posted on 2月 13, 2018 by Takaaki Naganoya

NSDataDetectorを用いて、自然言語テキスト(ここでは日本語のテキスト)から日付の情報を抽出するAppleScriptです。

AppleScript名:自然言語テキストから日付を抽出
— Created 2015-10-08 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions

set theDate to my getDatesIn:"本テキストには次の火曜日という日付情報を含んでいる。"
log theDate
–>  date "2015年10月13日火曜日 12:00:00"

set theDate to my getDatesIn:"本テキストには今度の土曜日という日付情報を含んでいる。"
log theDate
–>  date "2015年10月10日土曜日 12:00:00"

set theDate to my getDatesIn:"昨日うな重を食べた。"
log theDate
–>  date "2015年10月7日水曜日 12:00:00"

–set theDate to my getDatesIn:"一昨日何を食べたか覚えていない。"
–>  error number -2700 No date found

–set theDate to my getDatesIn:"The day after tommorow."

–set theDate to my getDatesIn:"相対日付の認識能力は低い。明後日はいつだ?"
–>  error number -2700 No date found

–set theDate to my getDatesIn:"本テキストには元旦という日付情報を含んでいる。" –This means 1/1 in next year
–>  error number -2700 No date found

on getDatesIn:aString
  set anNSString to current application’s NSString’s stringWithString:aString
  
set theDetector to current application’s NSDataDetector’s dataDetectorWithTypes:(current application’s NSTextCheckingTypeDate) |error|:(missing value)
  
set theMatch to theDetector’s firstMatchInString:anNSString options:0 range:{0, anNSString’s |length|()}
  
if theMatch = missing value then error "No date found with String:" & aString
  
set theDate to theMatch’s |date|()
  
return theDate as date
end getDatesIn:

★Click Here to Open This Script 

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

GMTとの時差を求める

Posted on 2月 13, 2018 by Takaaki Naganoya
AppleScript名:GMTとの時差を求める
set tDIff to (time to GMT) / 3600
–> 9.0

★Click Here to Open This Script 

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

UTCTime StringとNSDateの相互変換

Posted on 2月 13, 2018 by Takaaki Naganoya
AppleScript名:UTCTime StringとNSDateの相互変換
— Created 2015-02-24 by Shane Stanley
— Changed 2015-02-25 By Takaaki Naganoya
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aStr to retUTCTimeString()
–>   "2018-02-13T12:40:01.936"

set aNSDate to retNSDateFromUTCString(aStr) as date
–> date "2018年2月13日火曜日 21:39:43"

–Current Date -> UTCTime String
on retUTCTimeString()
  –There is need to get Current Calendar in my Time Zone
  
set aCalendar to current application’s NSCalendar’s currentCalendar()
  
set aTimeZone to (aCalendar’s timeZone)
  
set tDiff to (aTimeZone’s secondsFromGMT())
  
  
set theNSDateFormatter to current application’s NSDateFormatter’s alloc()’s init()
  
  
theNSDateFormatter’s setDateFormat:"yyyy-MM-dd’T’HH:mm:ss.SSS"
  
theNSDateFormatter’s setTimeZone:(current application’s NSTimeZone’s timeZoneForSecondsFromGMT:tDiff)
  
  
return (theNSDateFormatter’s stringFromDate:(current application’s NSDate’s |date|())) as text
end retUTCTimeString

–UTCTime String -> NSDate
on retNSDateFromUTCString(aText)
  set aStr to current application’s NSString’s stringWithString:aText
  
  
set theNSDateFormatter to current application’s NSDateFormatter’s alloc()’s init()
  
theNSDateFormatter’s setDateFormat:"yyyy-MM-dd’T’HH:mm:ss.SSS"
  
theNSDateFormatter’s setTimeZone:(current application’s NSTimeZone’s timeZoneForSecondsFromGMT:0)
  
  
return theNSDateFormatter’s dateFromString:aStr
end retNSDateFromUTCString

★Click Here to Open This Script 

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

ISO8601を考慮した週カウント v2

Posted on 2月 13, 2018 by Takaaki Naganoya

AppleScript名:ISO8601を考慮した週カウント v2
— Created 2016-02-10 by Takaaki Naganoya
— Modified 2016-03-26 by Takaaki Naganoya
— NSGregorianCalendar -> NSCalendarIdentifierGregorian
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aNSDate to makeNSDate(2016, 1, 1) of me
set aCal to current application’s NSCalendar’s currentCalendar()
aCal’s setMinimumDaysInFirstWeek:1
set aWN to (aCal’s components:(current application’s NSWeekCalendarUnit) fromDate:aNSDate)’s week()

aCal’s setMinimumDaysInFirstWeek:4 –ISO8601 Week Count
set bWN to (aCal’s components:(current application’s NSWeekCalendarUnit) fromDate:aNSDate)’s week()

return {aWN, bWN}
–>  {1, 52}

–Y,M,Dを指定してNSDateを作成
on makeNSDate(aYear as integer, aMonth as integer, aDay as integer)
  set aComp to current application’s NSDateComponents’s alloc()’s init()
  
aComp’s setDay:aDay
  
aComp’s setMonth:aMonth
  
aComp’s setYear:aYear
  
set aGrego to current application’s NSCalendar’s calendarWithIdentifier:(current application’s NSCalendarIdentifierGregorian)
  
set aDate to aGrego’s dateFromComponents:aComp
  
return aDate
end makeNSDate

★Click Here to Open This Script 

Posted in Calendar System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

ISO8601フォーマット日付のテキストをdateに変換

Posted on 2月 13, 2018 by Takaaki Naganoya
AppleScript名:ISO8601フォーマット日付のテキストをdateに変換
— Created 2015-08-28 20:19:04 +0900 by Takaaki Naganoya
— 2015 Piyomaru Software
— http://www.tondering.dk/claus/cal/iso8601.php
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use BridgePlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

set aStr to "2010-12-01T21:35:43+09:00"
BridgePlus’s datesFromStrings:{aStr} inFormat:"yyyy-MM-dd’T’HH:mm:ssZ"
–>  {​​​​​date "2010年12月1日水曜日 21:35:43"​​​}

set aStr to "2010-12-01 21:35:43"
BridgePlus’s datesFromStrings:{aStr} inFormat:"yyyy-MM-dd HH:mm:ss"
–>  {​​​​​date "2010年12月1日水曜日 21:35:43"​​​}

★Click Here to Open This Script 

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

ISO8601日付文字列を生成 v2

Posted on 2月 13, 2018 by Takaaki Naganoya
AppleScript名:ISO8601日付文字列を生成 v2
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"

set aDate to getDateInternational(2018, 12, 18, 9, 59, 35, "CET") –―year, month, date, hour, minute, second, time zone abbreviation.
set bStr to retISO8601DateTimeString(aDate, "CET") as string
–> "2018-12-18T09:59:35+01:00"

–NSDate -> ISO8601 Date & Time String
on retISO8601DateTimeString(targDate, timeZoneAbbreviation)
  set theNSDateFormatter to current application’s NSDateFormatter’s alloc()’s init()
  
theNSDateFormatter’s setDateFormat:"yyyy-MM-dd’T’HH:mm:ssZZZZZ" — Five zeds to get a colon in the time offset (except with GMT).
  
theNSDateFormatter’s setTimeZone:(current application’s NSTimeZone’s timeZoneWithAbbreviation:(timeZoneAbbreviation))
  
return (theNSDateFormatter’s stringFromDate:targDate) as text
end retISO8601DateTimeString

–Make a GMT Date Object with parameters from a given time zone.
on getDateInternational(aYear, aMonth, aDay, anHour, aMinute, aSecond, timeZoneAbbreviation)
  set theNSCalendar to current application’s NSCalendar’s currentCalendar()
  
theNSCalendar’s setTimeZone:(current application’s NSTimeZone’s timeZoneWithAbbreviation:(timeZoneAbbreviation))
  
set theDate to theNSCalendar’s dateWithEra:1 |year|:aYear |month|:aMonth |day|:aDay hour:anHour minute:aMinute |second|:aSecond nanosecond:0
  
return theDate as date
end getDateInternational

★Click Here to Open This Script 

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

date objectをRFC2822 date stringに変換

Posted on 2月 13, 2018 by Takaaki Naganoya
AppleScript名:date objectをRFC2822 date stringに変換
— Created 2017-12-19 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aDate to getDateInternational(2018, 2, 1) of me
set bStr to rfc2822DateTimeString(aDate, "JST") as string
–>  "Thu, 01 Feb 2018 00:00:00 +0900"

–date -> RFC2822 Date & Time String
on rfc2822DateTimeString(targDate, timeZoneName as string)
  set theNSDateFormatter to current application’s NSDateFormatter’s alloc()’s init()
  
theNSDateFormatter’s setDateFormat:"EEE, dd MMM yyyy HH:mm:ss Z"
  
theNSDateFormatter’s setTimeZone:(current application’s NSTimeZone’s alloc()’s initWithName:timeZoneName)
  
theNSDateFormatter’s setLocale:(current application’s NSLocale’s alloc()’s initWithLocaleIdentifier:"en_US_POSIX")
  
return (theNSDateFormatter’s stringFromDate:targDate) as text
end rfc2822DateTimeString

–Make Date Object from parameters
on getDateInternational(aYear as integer, aMonth as integer, aDay as integer)
  set theNSCalendar to current application’s NSCalendar’s currentCalendar()
  
set theDate to theNSCalendar’s dateWithEra:1 |year|:aYear |month|:aMonth |day|:aDay hour:0 minute:0 |second|:0 nanosecond:0
  
return theDate as date
end getDateInternational

★Click Here to Open This Script 

Posted in Calendar System Text | 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