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

バンドルIDで指定したプロセスを強制終了(NSRunningApplication)

Posted on 2月 8, 2018 by Takaaki Naganoya

バンドルIDで指定したプロセスを強制終了させるAppleScriptです。

Finderを終了させてみると、あえて意図して起動しないとFinderが終了したままの状態で戻って来ません。

AppleScript名:バンドルIDで指定したプロセスを強制終了(NSRunningApplication)
— Created 2017-09-17 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set pRes to forceQuitAProcessByBUndleID("com.apple.finder") of me

–指定プロセスの強制終了
on forceQuitAProcessByBUndleID(aBundleID)
  set appArray to current application’s NSRunningApplication’s runningApplicationsWithBundleIdentifier:aBundleID
  
if appArray’s |count|() > 0 then
    set appItem to appArray’s objectAtIndex:0
    
set aRes to (appItem’s terminate()) as boolean
    
return aRes
  else
    return false
  end if
end forceQuitAProcessByBUndleID

★Click Here to Open This Script 

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

他のアプリケーションを隠す

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:他のアプリケーションを隠す
— Created 2017-01-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

current application’s NSWorkspace’s sharedWorkspace()’s hideOtherApplications()

★Click Here to Open This Script 

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

指定名称のアプリケーションプロセスが存在すればその正しい名前を返す

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:指定名称のアプリケーションプロセスが存在すればその正しい名前を返す
— Created 2015-07-29 16:43:11 +0900 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aName to "メール"
set aRes to returnExactNameOfAnApp(aName) of me

on returnExactNameOfAnApp(aName)
  tell application "System Events"
    set ap1List to every process whose name is equal to aName
    
if ap1List = {} then
      set ap1List to every process whose displayed name is equal to aName
      
if ap1List = {} then return false
    end if
    
set anApp to contents of first item of ap1List
    
return name of anApp
  end tell
end returnExactNameOfAnApp

★Click Here to Open This Script 

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

ASOCで現在実行中のプロセスの情報を取得

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:ASOCで現在実行中のプロセスの情報を取得
— Created 2015-09-08 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set procInfo to current application’s NSProcessInfo’s processInfo()
–>  (NSProcessInfo) <NSProcessInfo: 0x6000000587e0>

set argList to procInfo’s arguments()
–>  (NSArray) {​​​​​"/Applications/ASObjC Explorer 4.app/Contents/MacOS/ASObjC Explorer 4"​​​}–ASObjC Explorer 4

set envList to procInfo’s environment()
–>  (NSDictionary) {​​​​​PATH:"/usr/bin:/bin:/usr/sbin:/sbin", ​​​​​TMPDIR:"/var/folders/h4/jfhlwst88xl9z0001s7k9vk00000gr/T/", ​​​​​LOGNAME:"me", ​​​​​HOME:"/Users/me", ​​​​​XPC_FLAGS:"0x0", ​​​​​Apple_PubSub_Socket_Render:"/private/tmp/com.apple.launchd.OLjjErklL4/Render", ​​​​​USER:"me", ​​​​​SSH_AUTH_SOCK:"/private/tmp/com.apple.launchd.y3g31V3gh7/Listeners", ​​​​​SECURITYSESSIONID:"XXXXX", ​​​​​DISPLAY:"/private/tmp/com.apple.launchd.63oTa9LGKM/org.macosforge.xquartz:0", ​​​​​XPC_SERVICE_NAME:"au.com.myriad-com.ASObjC-Explorer-4.69328", ​​​​​SHELL:"/bin/xxxx", ​​​​​__CF_USER_TEXT_ENCODING:"0x1F8:0x1:0xE"​​​}

set anUniqueStr to procInfo’s globallyUniqueString()
–>  (NSString) "XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX-XXXX-XXXXXXXXXXXXXXXX"

set anID to procInfo’s processIdentifier()
–>  4283–Unix Process ID (pid)

set aName to procInfo’s processName()
–>  (NSString) "ASObjC Explorer 4"

set aHostName to procInfo’s hostName()
–>  (NSString) "mbpretina.local"

set aVersionStr to procInfo’s operatingSystemVersionString()
–>  (NSString) "バージョン 10.10.5(ビルド 14F27)"

set aVersion to procInfo’s operatingSystemVersion()
–> can’t bridge argument of type {_NSOperatingSystemVersion=qqq}. OS X 10.10ではブリッジ不可。10.11でOK

set aCPUCores to procInfo’s processorCount()
–>  8

set activeCPUCores to procInfo’s activeProcessorCount()
–>  8

set anRAMcapacity to procInfo’s physicalMemory()
–>  8.589934592E+9

set anRAMcapacity to procInfo’s systemUptime()
–>  6.8344782485801E+4

set aThermalState to procInfo’s thermalState()
–>  0 –NSProcessInfoThermalStateNominal
(*
enum {
NSProcessInfoThermalStateNominal,
NSProcessInfoThermalStateFair,
NSProcessInfoThermalStateSerious,
NSProcessInfoThermalStateCritical
};
*)

★Click Here to Open This Script 

Posted in System | Tagged 10.11savvy 10.12savvy 10.13savvy | 1 Comment

ASOCでプロセス情報を取得

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:ASOCでプロセス情報を取得
— Created 2015-10-23 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set runningApplications to (current application’s NSWorkspace’s sharedWorkspace()’s runningApplications()) as list

repeat with i in runningApplications
  
  
set aName to (i’s localizedName()) as text
  
set anIcon to (i’s icon())
  
set anBundleID to (i’s bundleIdentifier()) as text
  
set anBundleURL to (i’s bundleURL())
  
  
set tmpArch to (i’s executableArchitecture())
  
if tmpArch = 16777223 then
    set anArch to "X86_64"
  else if tmpArch = 7 then
    set anArch to "I386 "
  else
    set anArch to "Another Arch (PPC? or Error)"
  end if
  
  
set anLaunchDate to (i’s launchDate())
  
set anFinishLaunch to (i’s isFinishedLaunching())
  
set aProcID to (i’s processIdentifier())
  
set anOwnMenubar to (i’s ownsMenuBar())
  
  
log {aName, tmpArch, anArch}
  
–> (* {"CCLibrary", -1, "Another Arch (PPC?)"} *)
end repeat

★Click Here to Open This Script 

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

NSRunningApplicationでアプリケーションプロセス情報を取得

Posted on 2月 8, 2018 by Takaaki Naganoya

AppleScriptで他のアプリケーションプロセスの情報を取得するには、OS標準装備のSystem Eventsに対して、

tell application "System Events"
	set aProp to properties of process "Safari"
end tell
--> {has scripting terminology:true, bundle identifier:"com.apple.Safari", file:alias "Macintosh HD:Applications:Safari.app:" of application "System Events", creator type:"sfri", subrole:missing value, entire contents:{}, selected:missing value, application file:alias "Cherry:Applications:Safari.app:" of application "System Events", orientation:missing value, role:"AXApplication", accepts high level events:true, file type:"APPL", value:missing value, position:missing value, id:909534, displayed name:"Safari", name:"Safari", class:application process, background only:false, frontmost:false, size:missing value, visible:true, Classic:false, role description:"application", maximum value:missing value, architecture:"x86_64", partition space used:0, short name:"Safari", focused:missing value, minimum value:missing value, help:missing value, title:"Safari", accepts remote events:false, total partition size:0, description:"application", accessibility description:missing value, enabled:missing value, unix id:3386}

などと操作することになります。ただし、System Eventsがつねに使えるわけではありません。

Mac App Storeに出すアプリケーションの中だと、些細な用途に他のアプリケーションを呼び出そうとしても、よほどの理由がないかぎり通りません(リジェクトされます)。Dark Mode/Light Modeの検出に安直にSystem Eventsを使おうとしてリジェクトされた経験があります。

そこで、他のサービス(shell commandとか、Cocoa Frameworkとか)を経由して機能を呼び出すことになります。まったく同じことができるわけではありませんが、1つの目的に対して複数の方法を用意しておくのはセオリーです。OS側でバグを作られた場合の回避策とか(正しくないOSバージョンを返してくるmacOSがありました)、目的に応じて利用に制限がかかる用途(まさにMac App Storeがそれです)があるためです。

AppleScript名:NSRunningApplicationでアプリケーションプロセス情報を取得
— Created 2017-09-17 15:27:23 +0900 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aBundleID to "com.apple.Safari"

set appArray to current application’s NSRunningApplication’s runningApplicationsWithBundleIdentifier:aBundleID
if appArray’s |count|() = 0 then its return

set appItem to appArray’s objectAtIndex:0

set iconRes to (appItem’s icon())
(*
–>  (NSImage) <NSImage 0x618001478f40 Size={32, 32} Reps=(
"<NSIconRefImageRep:0x61800029b300 iconRef=0x8403 size:128×128 pixels:128×128>",
"<NSIconRefImageRep:0x61800089f7c0 iconRef=0x8403 size:128×128 pixels:256×256>",
"<NSIconRefImageRep:0x6180006989c0 iconRef=0x8403 size:256×256 pixels:256×256>",
"<NSIconRefImageRep:0x61800129f040 iconRef=0x8403 size:256×256 pixels:512×512>",
"<NSIconRefImageRep:0x618000898dd0 iconRef=0x8403 size:512×512 pixels:512×512>",
"<NSIconRefImageRep:0x61800029a270 iconRef=0x8403 size:48×48 pixels:48×48>",
"<NSIconRefImageRep:0x618000691490 iconRef=0x8403 size:36×36 pixels:36×36>",
"<NSIconRefImageRep:0x618000c8e100 iconRef=0x8403 size:36×36 pixels:72×72>",
"<NSIconRefImageRep:0x618000a80460 iconRef=0x8403 size:32×32 pixels:32×32>",
"<NSIconRefImageRep:0x6180004899c0 iconRef=0x8403 size:32×32 pixels:64×64>",
"<NSIconRefImageRep:0x61800089db50 iconRef=0x8403 size:18×18 pixels:18×18>",
"<NSIconRefImageRep:0x618001291530 iconRef=0x8403 size:18×18 pixels:36×36>",
"<NSIconRefImageRep:0x618000c8e0b0 iconRef=0x8403 size:16×16 pixels:16×16>",
"<NSIconRefImageRep:0x618000880280 iconRef=0x8403 size:16×16 pixels:32×32>",
"<NSIconRefImageRep:0x618000e99a50 iconRef=0x8403 size:512×512 pixels:1024×1024>"
)>
*)


set locRes to (appItem’s localizedName()) as string
–>  "Safari"

set bID to (appItem’s bundleIdentifier()) as string
–>  "com.apple.Safari"

set bURL to (appItem’s bundleURL()) as string
–>  "Cherry:Applications:Safari.app:"

set arch to (appItem’s executableArchitecture())
–>  16777223

set exeURL to (appItem’s executableURL())
–>  (NSURL) file:///Applications/Safari.app/Contents/MacOS/Safari

set launchDate to (appItem’s launchDate())
–>  (NSDate) 2017-09-13 01:58:16 +0000

set launchFinish to (appItem’s finishedLaunching) as integer
–>  1

set pID to (appItem’s processIdentifier) as integer
–>  11877

set oenMenu to (appItem’s ownsMenuBar()) as boolean
–>  false

★Click Here to Open This Script 

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

アプレットのアイコンをDockに出さない2

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:アプレットのアイコンをDockに出さない2
— Created 2015-10-22 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

–Dockアイコン非表示、dialogも出ない
current application’s NSApp’s setActivationPolicy:(current application’s NSApplicationActivationPolicyProhibited)
repeat with i from 1 to 10
  tell current application
    display notification (i as text)
    
delay 1
  end tell
end repeat
quit

★Click Here to Open This Script 

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

Dockとメニューバーを隠す→戻す

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:Dockとメニューバーを隠す→戻す
— Created 2017-03-15 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

–Main MenuとDockを隠す
current application’s NSApplication’s sharedApplication()’s setPresentationOptions:10 –NSApplicationPresentationHideMenuBar | NSApplicationPresentationHideDock

delay 10

–MenuとDockを通常に戻す
current application’s NSApplication’s sharedApplication()’s setPresentationOptions:(current application’s NSApplicationPresentationDefault)

★Click Here to Open This Script 

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

Dockアイコンにプログレスバーを追加

Posted on 2月 8, 2018 by Takaaki Naganoya

Dockアイコンにプレグレスバーを描画するAppleScriptです。

書き方のクセがあからさまに違うこの内容は、Edama2さんからいただいたものですね、コレ。

–> Demo Movie

AppleScript名:Dockアイコンにプログレスバーを追加
use AppleScript
use framework "Foundation"
use scripting additions

on run
  set max to 100
  
repeat with num from 1 to max
    my progDockTile(max, num)
    
delay 0.1
  end repeat
  
  
#アイコンを元に戻す
  
current application’s NSApp’s setApplicationIconImage:(current application’s NSImage’s imageNamed:"NSApplicationIcon")
end run

#Dockアイコンにプログレスバーを追加
on progDockTile(max, current)
  set appIcon to current application’s NSImage’s imageNamed:"NSApplicationIcon"
  
set iconSize to appIcon’s |size|()
  
  
tell (current application’s NSImage’s alloc()’s initWithSize:iconSize)
    
    
lockFocus()
    
    
appIcon’s dissolveToPoint:(current application’s NSZeroPoint) fraction:1.0
    
set n to (iconSize’s width) / 16
    
    
#プログレスバーの長方形
    
set myRect to current application’s NSMakeRect(n / 2, n, n * 15, n * 1.6) –>{origin:{x:4.0, y:8.0}, |size|:{width:120.0, height:12.800000190735}}
    
    
tell (current application’s NSBezierPath’s ¬
      bezierPathWithRoundedRect:myRect ¬
        xRadius:(myRect’s |size|’s height) / 2 ¬
        
yRadius:(myRect’s |size|’s height) / 2)
      
      
current application’s (NSColor’s colorWithWhite:1.0 alpha:0.4)’s |set|() –>背景色
      
fill()
      
      
current application’s NSColor’s whiteColor()’s |set|() –>枠色
      
stroke()
    end tell
    
    
if current is greater than 0 then
      
      
if current is greater than max then set current to max
      
      
set myRect’s |size|’s width to (myRect’s |size|’s width) / max * current
      
      
tell (current application’s NSBezierPath’s ¬
        bezierPathWithRoundedRect:myRect ¬
          xRadius:(myRect’s |size|’s height) / 2 ¬
          
yRadius:(myRect’s |size|’s height) / 2)
        
        
set strartColor to current application’s NSColor’s colorWithRed:0.15 green:0.55 blue:1 alpha:0.8
        
set endColor to strartColor’s shadowWithLevel:0.7
        
set grad to current application’s NSGradient’s alloc()’s initWithStartingColor:strartColor endingColor:endColor
        
grad’s drawInBezierPath:it angle:270.0
      end tell
    end if
    
    
unlockFocus()
    
    
current application’s NSApp’s setApplicationIconImage:it
  end tell
  
  
return (current + 1)
end progDockTile

★Click Here to Open This Script 

Posted in Icon Image System | Tagged 10.11savvy 10.12savvy 10.13savvy Dock | 1 Comment

アプリケーションのDockアイコンに文字列をバッジ表示(5文字まで)

Posted on 2月 8, 2018 by Takaaki Naganoya

AppleScript名:アプリケーションのDockアイコンに文字列をバッジ表示(5文字まで)
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit" –初版では入っておらず、環境によってはクラッシュした。後から追記

showDockBadge_("")

delay 1

showDockBadge_("77777") –Max 5 文字

delay 5

showDockBadge_("")

–Dockのアプリケーションアイコンに指定文字をバッジ表示
on showDockBadge:theText
  set theDockTile to current application’s NSApp’s dockTile()
  
theDockTile’s setBadgeLabel:theText
  
theDockTile’s display()
end showDockBadge:

★Click Here to Open This Script 

Posted in Icon Image System | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy Dock | Leave a comment

Dockアイコンをバウンドさせる

Posted on 2月 8, 2018 by Takaaki Naganoya

対象のアプリケーションが最前面にいるとDock上でアイコンがバウンドしないので、強制的に他のアプリケーション(Finder)を最前面に出してから実行しています。

AppleScript名:Dockアイコンをバウンドさせる
— Created 2015-09-08 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

tell application "Finder" to activate –Script Editor/ASObjC Explorer 4を背面に

set anApp to current application’s NSApplication’s sharedApplication()
anApp’s requestUserAttention:(current application’s NSCriticalRequest)

★Click Here to Open This Script 

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

指定ファイルからカスタムアイコンを削除する

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:指定ファイルからカスタムアイコンを削除する
— Created 2015-10-19 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aFile to POSIX path of (choose file with prompt "Choose Target File") –設定対象のファイル
set aSW to current application’s NSWorkspace’s sharedWorkspace()
aSW’s setIcon:(missing value) forFile:aFile options:0

★Click Here to Open This Script 

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

指定ファイルに指定アイコン画像をつける

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:指定ファイルに指定アイコン画像をつける
— Created 2015-10-19 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aPath to POSIX path of (choose file of type {"com.apple.icns", "public.tiff"} with prompt "Choose Icon File") –アイコンファイル
set aFile to POSIX path of (choose file with prompt "Choose Target File") –設定対象のファイル

set aURL to current application’s |NSURL|’s fileURLWithPath:aPath
set aImage to current application’s NSImage’s alloc()’s initWithContentsOfURL:aURL

set aSW to current application’s NSWorkspace’s sharedWorkspace()
aSW’s setIcon:aImage forFile:aFile options:0

★Click Here to Open This Script 

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

指定フォルダからカスタムアイコンを削除する v3

Posted on 2月 8, 2018 by Takaaki Naganoya

指定のフォルダに指定されていたアイコン画像を削除するAppleScriptです。

特定のフォルダを監視して、ファイルが追加されたり削除されたりすると、指定のAppleScriptを実行する仕組み「フォルダアクション」がmacOSに標準装備されています。

フォルダアクションはフォルダアクションでいいのですが、あまり融通が効かないので、フォルダアクションを使わずにAppleScript独自でフォルダを監視することはよくあります。

そして、監視対象に指定したフォルダのアイコンを変更し、わかりやすく「監視対象である」ことをユーザーに伝えることも、よくある話です。そして、監視処理が終了したあとでフォルダのアイコンをOS標準の元のものに戻しておく必要があります。本Scriptはそういう処理に用いるものです。

AppleScript名:指定フォルダからカスタムアイコンを削除する v3
— Created 2015-10-21by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aFolder to POSIX path of (choose folder with prompt "Choose Target Folder") –カスタムアイコン削除対象のフォルダ
removeCustomIcon(aFolder) of me

on removeCustomIcon(aFolder)
  set aSW to current application’s NSWorkspace’s sharedWorkspace()
  
aSW’s setIcon:(missing value) forFile:aFolder options:0 –Erase
  
  
tell application "Finder"
    update ((POSIX file aFolder) as alias) –Refresh State
  end tell
end removeCustomIcon

★Click Here to Open This Script 

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

指定フォルダに指定アイコン画像をつける v3

Posted on 2月 8, 2018 by Takaaki Naganoya

指定のフォルダに指定アイコン画像をつけるAppleScriptです。

特定のフォルダを監視して、ファイルが追加されたり削除されたりすると、指定のAppleScriptを実行する仕組み「フォルダアクション」がmacOSに標準装備されています。

フォルダアクションはフォルダアクションでいいのですが、あまり融通が効かないので、フォルダアクションを使わずにAppleScript独自でフォルダを監視することはよくあります。

そして、監視対象に指定したフォルダのアイコンを変更し、わかりやすく「監視対象である」ことをユーザーに伝えることも、よくある話です。本Scriptはそういう処理に用いるものです。

もちろん、処理が終了したあとは監視対象フォルダのアイコンは元に戻しておくべきで、「指定フォルダからカスタムアイコンを削除する v3」とペアで使っています。

AppleScript名:指定フォルダに指定アイコン画像をつける v3
— Created 2015-10-21 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set anIconPath to POSIX path of (choose file of type {"com.apple.icns", "public.tiff"} with prompt "Choose Icon File")
set aFolder to POSIX path of (choose folder with prompt "Choose Folder")
setCustomIcon(anIconPath, aFolder) of me

on setCustomIcon(aPath, aFolder)
  set aFolderPath to current application’s NSString’s stringWithString:aFolder
  
  
set aURL to current application’s |NSURL|’s fileURLWithPath:aPath
  
set aImage to current application’s NSImage’s alloc()’s initWithContentsOfURL:aURL
  
  
set aSW to current application’s NSWorkspace’s sharedWorkspace()
  
aSW’s setIcon:(missing value) forFile:aFolder options:0 –Erase
  
tell application "Finder"
    update ((POSIX file aFolder) as alias) –Refresh State
  end tell
  
  
aSW’s setIcon:aImage forFile:aFolderPath options:0 –Write
  
tell application "Finder"
    update ((POSIX file aFolder) as alias) –Refresh State
  end tell
end setCustomIcon

★Click Here to Open This Script 

Posted in folder Icon System | Tagged 10.11savvy 10.12savvy 10.13savvy | 1 Comment

指定ファイルのxattrの削除(ダウンロードしたファイルが開けないときに)

Posted on 2月 8, 2018 by Takaaki Naganoya

–> XAttribute.framework

AppleScript名:指定ファイルのxattrの削除(ダウンロードしたファイルが開けないときに)
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "XAttribute" –https://github.com/rylio/OTMXAttribute

set dlFullPath to POSIX path of (choose file)

set xRes to removeXAttrFromFile(dlFullPath, "com.apple.quarantine")

on removeXAttrFromFile(aFile, anXattr)
  –Get Xattr String
  
set anAttribute to (current application’s OTMXAttribute’s stringAttributeAtPath:aFile |name|:anXattr |error|:(missing value))
  
if anAttribute = missing value then return true –There is no use to remove xattr
  
  
–Remove Xattr
  
set xRes to (current application’s OTMXAttribute’s removeAttributeAtPath:aFile |name|:anXattr |error|:(missing value))
  
if xRes = missing value then return false
  
return (xRes as boolean)
end removeXAttrFromFile

★Click Here to Open This Script 

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

指定EnumがどのFrameworkに所属しているか検索 v2

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:指定EnumがどのFrameworkに所属しているか検索 v2
— Created 2017-10-13 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property NSFileManager : a reference to current application’s NSFileManager
property NSString : a reference to current application’s NSString
property NSPredicate : a reference to current application’s NSPredicate
property NSMutableArray : a reference to current application’s NSMutableArray
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding

set a1Res to searchEnumFromHeaderFiles("NSUTF8StringEncoding") of me
–>  {​​​​​"DiscRecording.framework", ​​​​​"Foundation.framework", ​​​​​"SpriteKit.framework"​​​}

set a2Res to searchEnumFromHeaderFiles("NSNumberFormatterRoundUp") of me
–>  {​​​​​"Foundation.framework"​​​}

set a3Res to searchEnumFromHeaderFiles("NSParagraphStyleAttributeName") of me
–>  {​​​​​"AppKit.framework"​​​}

on searchEnumFromHeaderFiles(targString)
  set aClass to current application’s NSClassFromString(targString)
  
if aClass is not equal to missing value then return false
  
  
set dPath to POSIX path of (path to application id "com.apple.dt.Xcode")
  
set aFol to dPath & "Contents/Developer/Platforms/MacOSX.platform/" & "Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
  
  
set bList to retFullPathWithinAFolderWithRecursiveFilterByExt(aFol, "h") of me
  
set matchedList to {}
  
  
repeat with i in bList
    set j to contents of i
    
    
set aStr to (NSString’s stringWithContentsOfFile:j encoding:NSUTF8StringEncoding |error|:(missing value))
    
if aStr ≠ missing value then
      set aRange to (aStr’s rangeOfString:targString)
      
      
if aRange’s location() ≠ current application’s NSNotFound and (aRange’s location()) < 9.99999999E+8 then
        set tmpStr to (current application’s NSString’s stringWithString:j)
        
set pathList to tmpStr’s pathComponents()
        
set thePred to (current application’s NSPredicate’s predicateWithFormat:"pathExtension == ’framework’")
        
set aRes to (pathList’s filteredArrayUsingPredicate:thePred)’s firstObject() as text
        
set the end of matchedList to aRes
      end if
      
    end if
  end repeat
  
  
set aArray to current application’s NSArray’s arrayWithArray:matchedList
  
set bArray to aArray’s valueForKeyPath:"@distinctUnionOfObjects.self"
  
return bArray as list
end searchEnumFromHeaderFiles

–指定フォルダ以下のすべてのファイルを再帰で取得(拡張子で絞り込み)
on retFullPathWithinAFolderWithRecursiveFilterByExt(aFol, aExt)
  set anArray to NSMutableArray’s array()
  
set aPath to NSString’s stringWithString:aFol
  
set dirEnum to NSFileManager’s defaultManager()’s enumeratorAtPath:aPath
  
  
repeat
    set aName to (dirEnum’s nextObject())
    
if aName = missing value then exit repeat
    
set aFullPath to aPath’s stringByAppendingPathComponent:aName
    
anArray’s addObject:aFullPath
  end repeat
  
  
set thePred to NSPredicate’s predicateWithFormat:"pathExtension == [c]%@" argumentArray:{aExt}
  
set bArray to anArray’s filteredArrayUsingPredicate:thePred
  
  
return bArray as list
end retFullPathWithinAFolderWithRecursiveFilterByExt

★Click Here to Open This Script 

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

指定クラスがどのFrameworkに所属しているか検索 v3

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:指定クラスがどのFrameworkに所属しているか検索 v3
— Created 2017-10-14 by Shane Stanley
— Modified 2017-10-14 by Takaaki Naganoya
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set fRes1 to searchClassInFrameworks("JSContext") of me
–>  "JavaScriptCore.framework"

set fRes2 to searchClassInFrameworks("NSApplication") of me
–>  "AppKit.framework"

set fRes3 to searchClassInFrameworks("NSRect") of me
–>  false

set fRes4 to searchClassInFrameworks("PDFPage") of me
–>  "Quartz.framework"

set fRes5 to searchClassInFrameworks("NSUTF8StringEncoding") of me
–>  false

set fRes6 to searchClassInFrameworks("CIColor") of me
–>  "CoreImage.framework"

on searchClassInFrameworks(aTarget)
  set aClass to current application’s NSClassFromString(aTarget)
  
if aClass = missing value then return false
  
set theComponenents to (current application’s NSBundle’s bundleForClass:aClass)’s bundleURL’s pathComponents()
  
set thePred to current application’s NSPredicate’s predicateWithFormat:"pathExtension == ’framework’"
  
set aRes to (theComponenents’s filteredArrayUsingPredicate:thePred)’s firstObject() as text
  
return aRes
end searchClassInFrameworks

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | 1 Comment

指定スクリプト書類の記述OSA言語を取得する v2

Posted on 2月 8, 2018 by Takaaki Naganoya
AppleScript名:指定スクリプト書類の記述OSA言語を取得する v2
— Created 2017-06-04 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"

set anAlias to choose file of type {"com.apple.applescript.script", "com.apple.applescript.script-bundle"}
set sRes to getOSALangKindFromScriptFile(anAlias) of me
–>  {​​​​​osaName:"AppleScript", ​​​​​osaDesc:"AppleScript.", ​​​​​osaVer:"2.5"​​​}
–>  {​​​​​osaName:"JavaScript", ​​​​​osaDesc:"JavaScript", ​​​​​osaVer:"1.1"​​​}

on getOSALangKindFromScriptFile(anAlias)
  set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of anAlias)
  
set theScript to current application’s OSAScript’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value)
  
  
set scriptName to theScript’s |language|()’s |name|() as string
  
set scriptDesc to theScript’s |language|()’s info() as string
  
set scriptVer to theScript’s |language|()’s |version|() as string
  
  
return {osaName:scriptName, osaDesc:scriptDesc, osaVer:scriptVer}
end getOSALangKindFromScriptFile

★Click Here to Open This Script 

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

データのClassを求める

Posted on 2月 8, 2018 by Takaaki Naganoya

データのclassを求めるAppleScriptです。

AppleScriptではもともと、

class of 変数

で、変数に入っているデータのclassが求められます。ただ、CocoaのオブジェクトのClassは求められないので、このようなScriptを書いてみた次第です。

AppleScript名:データのClassを求める
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set theValue to "10"
set aClass to getClassFromData(theValue) of me
–> "text"

set cRes to getClassFromData(current application’s NSArray’s arrayWithArray:{1, 2, 3}) of me
–> "NSArray"

tell application "System Events"
  set a to process "Finder"
end tell
set dClass to getClassFromData(a) of me
–> "application process"

tell application "Safari"
  if running then
    if (count of every document) > 0 then
      set a to front document
      
set eClass to getClassFromData(a) of me
      
–> "document"
    end if
  end if
end tell

on getClassFromData(aData)
  set aRes to (count {aData} each reference)
  
  
if aRes = 0 then
    –Pure AppleScript Object
    
try
      return (class of aData) as string
    on error
      return false
    end try
  else
    –NSObject
    
set nsObjRes to getClassNameStringFromObject(aData) of me
    
if nsObjRes = false then
      –Maybe application Object
      
return (class of aData) as string
    else
      return nsObjRes –NSObject
    end if
  end if
end getClassFromData

on getClassNameStringFromObject(aObject)
  set classList to {"AddressBook", "AVAsset", "AVAssetExportSession", "AVAudioPlayer", "CGPointZero", "CGPostMouseEvent", "CIColor", "CIFilter", "CIImage", "CIVector", "CLLocation", "CLLocationManager", "CWInterface", "EKAlarm", "EKEventStore", "EKStructuredLocation", "FSEvent", "IOBluetoothDevice", "IOBluetoothHostController", "ITLibrary", "JSContext", "MKMapView", "Myriad Helpers", "NSAffineTransform", "NSAlert", "NSAnimationContext", "NSApp", "NSApplication", "NSArray", "NSAttributedString", "NSAutoreleasePool", "NSBezierPath", "NSBitmapImageRep", "NSBox", "NSBundle", "NSButton", "NSByteCountFormatter", "NSCalendar", "NSCharacterSet", "NSClassFromString", "NSColor", "NSColorList", "NSColorSpace", "NSColorWell", "NSComboBox", "NSCompoundPredicate", "NSCountedSet", "NSData", "NSDataDetector", "NSDate", "NSDateComponents", "NSDateFormatter", "NSDateIntervalFormatter", "NSDatePicker", "NSDecimalNumber", "NSDictionary", "NSEnergyFormatter", "NSError", "NSEvent", "NSFileManager", "NSFileSystemFreeSize", "NSFont", "NSFontCollection", "NSFontManager", "NSGraphicsContext", "NSHelpManager", "NSHomeDirectory", "NSHost", "NSImage", "NSImageView", "NSIndexSet", "NSIntersectionRect", "NSInvocationOperation", "NSJSONSerialization", "NSLengthFormatter", "NSLinguisticTagger", "NSLocale", "NSLocaleIdentifier", "NSLog", "NSMakePoint", "NSMakeRange", "NSMakeRect", "NSMapTable", "NSMassFormatter", "NSMatrix", "NSMenuItem", "NSMetadataQuery", "NSMutableArray", "NSMutableAttributedString", "NSMutableCharacterSet", "NSMutableData", "NSMutableDictionary", "NSMutableIndexSet", "NSMutableSet", "NSMutableString", "NSMutableURLRequest", "NSNetServiceBrowser", "NSNotificationCenter", "NSNumber", "NSNumberFormatter", "NSNumberFormatterRoundDown", "NSNumberFormatterRoundUp", "NSOpenPanel", "NSOperationQueue", "NSOrderedSet", "NSPasteboard", "NSPasteboardItem", "NSPipe", "NSPNGFileType", "NSPointInRect", "NSPopUpButton", "NSPredicate", "NSPrinter", "NSPrintInfo", "NSPrintOperation", "NSProcessInfo", "NSPropertyListFormat", "NSPropertyListImmutable", "NSPropertyListSerialization", "NSRange", "NSRect", "NSRegularExpression", "NSRegularExpressionAnchorsMatchLines", "NSRegularExpressionDotMatchesLineSeparators", "NSRegularExpressionSearch", "NSRunningApplication", "NSSavePanel", "NSScanner", "NSScreen", "NSScriptCommand", "NSSegmentedControl", "NSSet", "NSShadow", "NSSharingService", "NSSlider", "NSSortDescriptor", "NSSound", "NSSpeechRecognizer", "NSSpeechSynthesizer", "NSSpellChecker", "NSSplitView", "NSStatusBar", "NSString", "NSTableColumn", "NSTableView", "NSTask", "NSTextField", "NSTextView", "NSThread", "NSTimeInterval", "NSTimer", "NSTimeZone", "NSUnarchiver", "NSUnionRect", "NSURL", "NSURLComponents", "NSURLConnection", "NSURLDownload", "NSURLQueryItem", "NSURLRequest", "NSURLRequestReloadIgnoringLocalCacheData", "NSUserDefaults", "NSUTF8StringEncoding", "NSUUID", "NSView", "NSWeekCalendarUnit", "NSWindow", "NSWindowController", "NSWorkspace", "NSXMLParser", "NSZeroRect", "NSZeroSize", "ODNode", "ODQuery", "ODSession", "OSAScript", "OSAScriptController", "OSAScriptView", "PDFAnnotation", "PDFDestination", "PDFDocument", "PDFOutline", "PDFPage", "PDFThumbnailView", "PDFView", "QCView", "SBApplication", "WebView", "WKWebView"}
  
  
repeat with i in classList
    set j to contents of i
    
set aClass to current application’s NSClassFromString(j)
    
try
      set aRes to (aObject’s isKindOfClass:aClass) as boolean
    on error
      –May be an Application Object
      
return false
    end try
    
    
if aRes = true then return j
  end repeat
  
  
return false
end getClassNameStringFromObject

★Click Here to Open This Script 

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

Post navigation

  • Older posts
  • Newer posts

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

Google Search

Popular posts

  • Numbersで選択範囲のセルの前後の空白を削除
  • macOS 26, Tahoe
  • macOS 15でも変化したText to Speech環境
  • KagiのWebブラウザ、Orion
  • Script Debuggerの開発と販売が2025年に終了
  • 【続報】macOS 15.5で特定ファイル名パターンのfileをaliasにcastすると100%クラッシュするバグ
  • macOS 15 リモートApple Eventsにバグ?
  • NSObjectのクラス名を取得 v2.1
  • 2024年に書いた価値あるAppleScript
  • 有害ではなくなっていたSpaces
  • macOS 15:スクリプトエディタのAppleScript用語辞書を確認できない
  • Xcode上のAppleScriptObjCのプログラムから、Xcodeのログ欄へのメッセージ出力を実行
  • (確認中)AppleScript Dropletのバグっぽい動作が解消?
  • AVSpeechSynthesizerで読み上げテスト
  • AppleScript Dropletのバグっぽい動作が「復活」(macOS 15.5β)
  • Apple、macOS標準搭載アプリ「写真」のバージョン表記を間違える
  • 指定フォルダ以下の画像のMD5チェックサムを求めて、重複しているものをピックアップ
  • macOS 26, 15.5でShortcuts.app「AppleScriptを実行」アクションのバグが修正される
  • Numbersで選択中の2列のセルを比較して並べ直して書き戻す v2
  • Script Debuggerがフリーダウンロードで提供されることに

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1391) 10.14savvy (587) 10.15savvy (438) 11.0savvy (283) 12.0savvy (212) 13.0savvy (204) 14.0savvy (159) 15.0savvy (156) CotEditor (66) Finder (52) 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 (56) Pixelmator Pro (20) Safari (44) Script Editor (27) WKUserContentController (21) WKUserScript (20) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

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

アーカイブ

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

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

メタ情報

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

Forum Posts

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

メタ情報

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