AppleScript Script Menu

[com.apple.ScriptEditor]AppleScriptをターミナルで実行する

行頭
#!/usr/bin/env osascript


必須です

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application

property strBundleID : "com.apple.ScriptEditor"

tell application "Script Editor"
  activate
  tell front window
    tell front document
      set strFilePath to path as text
      set boolmodified to modified
      if boolmodified is true then
save
      end if
    end tell
  end tell
end tell

##パス
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidExtensionName to ocidFilePath's pathExtension()

##アトリビュート 実行できるようにアクセス権755
set ocidAttrArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
set ocidAttDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set ocidLogValue to refMe's NSNumber's numberWithUnsignedLong:(493)
ocidAttDict's setValue:(ocidLogValue) forKey:(refMe's NSFilePosixPermissions)
##アクセス権を設定
set appFileManager to refMe's NSFileManager's defaultManager()
appFileManager's setAttributes:(ocidAttDict) ofItemAtPath:(ocidFilePath) |error|:(reference)

###scptでは実行出来ないのでapplescript(テキスト形式)にする
if (ocidExtensionName as text) is "scpt" then
  set ocidBaseFilePath to ocidFilePath's stringByDeletingPathExtension()
  set ocidScriptFilePath to ocidBaseFilePath's stringByAppendingPathExtension:("applescript")
  set ocidScriptFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidScriptFilePath) isDirectory:false
  set aliasScriptFilePath to (ocidScriptFilePathURL's absoluteURL()) as «class furl»
  set strFilePath to aliasScriptFilePath's |path| as text
  tell application "Script Editor"
    activate
    tell front window
      tell front document
save in aliasScriptFilePath
      end tell
    end tell
  end tell
end if
#パスを整形して
set strCommandText to ("\"" & strFilePath & "\"")
###ターミナルで実行する
tell application "Terminal"
  launch
  activate
  set objWindowID to (do script "\n\n")
  delay 0.5
do script strCommandText in objWindowID
end tell


|

com.apple.AppleScriptUtility


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

tell application "AppleScript Utility"
  launch
  properties
end tell

tell application id "com.apple.AppleScriptUtility"
  activate
  set application scripts position to top
  set Script menu enabled to true
  set show Computer scripts to true
end tell

tell application "System Events"
  set folder actions enabled to true
end tell

tell application id "com.apple.AppleScriptUtility"
  ##read only
GUI Scripting enabled
UI elements enabled
end tell

tell application "System Events"
  ##read only
  UI elements enabled
  script menu enabled
end tell

tell application id "com.apple.AppleScriptUtility"
  set aliasFilePath to default script editor
end tell

tell application "System Events"
  activate
return UI elements enabled
end tell




|

スクリプトメニューやコマンドラインから実行させない

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


##############################
#####スクリプトメニューから実行させない
##############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    set aliasPathToMe to path to me as alias
    tell application "Script Editor"
      open aliasPathToMe
    end tell
    return "中止しました"
  end tell
else
  tell current application
    activate
  end tell
end if



【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

##############################
#####ダイアログを前面に
##############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
doDisplayAlert()
else
  tell current application to activate
doDisplayAlert()
end if



on doDisplayAlert()
  
  display alert ""
  
end doDisplayAlert

|

スクリプトメニューを有効にする

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

#############################
###設定
#############################

do shell script "/usr/bin/defaults write com.apple.ScriptMenuApp \"NSStatusItem Visible com.apple.scriptmenu\"  -bool true"
do shell script "/usr/bin/defaults write com.apple.scriptmenu PutAppScriptsFirst -bool true"
do shell script "/usr/bin/defaults write com.apple.scriptmenu ScriptMenuEnabled -bool true"
do shell script "/usr/bin/defaults write com.apple.scriptmenu ShowLibraryScripts -bool true"

do shell script "/usr/bin/defaults read com.apple.scriptmenu"
do shell script "/usr/bin/defaults read com.apple.ScriptMenuApp"

#############################
###CFPreferencesを再起動
#############################
#####CFPreferencesを再起動
set strCommandText to "/usr/bin/killall cfprefsd" as text
do shell script strCommandText
delay 2


#############################
###スクリプトメニューを有効にする
#############################
tell application id "com.apple.ScriptMenuApp"
  launch
  activate
end tell


|

[Tools]パーミッション値 8進数→10進数

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
#                       com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/FinderIcon.icns" as alias
set strDefaultAnswer to "666" as text

set strText to "777-->511\n775-->509\n770-->504\n755-->493\n750-->488\n700-->448\n555-->365\n333-->219"

try
    set recordResponse to (display dialog strText with title "3桁8進数を入力" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer)
    
on error
    log "エラーしました"
    return "エラーしました"
    error number -128
end try
if true is equal to (gave up of recordResponse) then
    return "時間切れですやりなおしてください"
    error number -128
end if
if "OK" is equal to (button returned of recordResponse) then
    set strResponse to (text returned of recordResponse) as text
else
    log "エラーしました"
    return "エラーしました"
    error number -128
end if

set strDem to doOct2Dem(strResponse)


try
    set objResponse to (display alert ("計算結果:" & strDem) buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" as informational giving up after 30)
on error
    log "エラーしました"
    return
end try

###################################
#####パーミッション 8進10進
###################################

to doOct2Dem(argOctNo)
    set strOctalText to argOctNo as text
    set num3Line to first item of strOctalText as number
    set num2Line to 2nd item of strOctalText as number
    set num1Line to last item of strOctalText as number
    set numDecimal to (num3Line * 64) + (num2Line * 8) + (num1Line * 1)
    return numDecimal
end doOct2Dem

|

[Script menu]スクリプトメニューから実行した時の分岐

実にバカらしい…とほ

#!/usr/bin/env osascript

----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

#

#

#

#

#                       com.cocolog-nifty.quicktimer.icefloe

----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

##自分環境がos12なので2.8にしているだけです

use AppleScript version "2.4"

use framework "Foundation"

use scripting additions


property refMe : a reference to current application

property refNSURL : a reference to refMe's NSURL



set strUTI to "com.google.Chrome" as text

set strAppName to "Google Chrome" as text


########スクリプトメニュー判定

tell current application

  set strName to name as text

end tell

if strName is "osascript" then

  set aliasAppPath to path to application strAppName as alias

  tell application "Finder"

    open aliasAppPath

  end tell

  tell application strAppName

    launch

    activate

  end tell

  return "起動"

else

  set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue

  set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue

  

  set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:strUTI

  set ocidAppBundlePathURL to ocidAppBundle's bundleURL()

  set strAppName to (ocidAppBundle's objectForInfoDictionaryKey:"CFBundleDisplayName") as text

  

  set ocidOpenConfiguration to refMe's NSWorkspaceOpenConfiguration's configuration()

  ocidOpenConfiguration's setHides:ocidFalse

  ocidOpenConfiguration's setRequiresUniversalLinks:ocidFalse

  ocidOpenConfiguration's setActivates:ocidTrue

  (refMe's NSWorkspace's sharedWorkspace())'s openApplicationAtURL:ocidAppBundlePathURL configuration:(ocidOpenConfiguration) completionHandler:(missing value)

end if












|

[com.apple.scriptmenu] defaults

sh-3.2$ 

sh-3.2$ 

sh-3.2$ 

sh-3.2$ /usr/bin/defaults write com.apple.scriptmenu PutAppScriptsFirst -bool true

sh-3.2$ /usr/bin/defaults write com.apple.scriptmenu ScriptMenuEnabled -bool true

sh-3.2$ /usr/bin/defaults write com.apple.scriptmenu ShowLibraryScripts -bool true

sh-3.2$ 

sh-3.2$ 

sh-3.2$ /usr/bin/defaults read com.apple.scriptmenu

{

    PutAppScriptsFirst = 1;

    ScriptMenuEnabled = 1;

    ShowLibraryScripts = 1;

}

sh-3.2$ 

sh-3.2$ 

sh-3.2$ 

sh-3.2$ /usr/bin/defaults write com.apple.ScriptMenuApp "NSStatusItem Visible com.apple.scriptmenu"  -bool true

sh-3.2$ 

sh-3.2$ 

sh-3.2$ /usr/bin/defaults read com.apple.ScriptMenuApp

{

    "NSStatusItem Visible com.apple.scriptmenu" = 1;

}

sh-3.2$ 

sh-3.2$ 


do shell script "/usr/bin/defaults write com.apple.ScriptMenuApp \"NSStatusItem Visible com.apple.scriptmenu\" -bool true"

do shell script "/usr/bin/defaults write com.apple.scriptmenu PutAppScriptsFirst -bool true"
do shell script "/usr/bin/defaults write com.apple.scriptmenu ScriptMenuEnabled -bool true"
do shell script "/usr/bin/defaults write com.apple.scriptmenu ShowLibraryScripts -bool true"

do shell script "/usr/bin/defaults read com.apple.scriptmenu"

do shell script "/usr/bin/defaults read com.apple.ScriptMenuApp"

|

[com.apple.scriptmenu] mobileconfig

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>


  <key>PayloadContent</key>

  <array>

    <!-- com.apple.ScriptMenuApp -->

    <dict>

      <key>NSStatusItem Visible com.apple.scriptmenu</key>

      <true/>

      <key>PayloadDisplayName</key>

      <string>com.apple.ScriptMenuApp</string>

      <key>PayloadIdentifier</key>

      <string>8A67C180-59F5-4EEC-B27F-952ACBDC5CF4</string>

      <key>PayloadType</key>

      <string>com.apple.ScriptMenuApp</string>

      <key>PayloadUUID</key>

      <string>3083A2E1-AABB-4600-A5E2-336FEC81B79D</string>

      <key>PayloadVersion</key>

      <integer>1</integer>

    </dict>

    <!-- com.apple.scriptmenu -->

    <dict>

      <key>ScriptMenuEnabled</key>

        <true/>

      <key>PutAppScriptsFirst</key>

        <true/>

      <key>ShowLibraryScripts</key>

        <false/>


      <key>PayloadDisplayName</key>

      <string>com.apple.scriptmenu</string>

      <key>PayloadIdentifier</key>

      <string>EBCA53F0-23BA-42F5-804E-2BCB7855595C</string>

      <key>PayloadType</key>

      <string>com.apple.scriptmenu</string>

      <key>PayloadUUID</key>

      <string>A4302839-5623-4128-8F6B-FB91EC185CAD</string>

      <key>PayloadVersion</key>

      <integer>1</integer>

    </dict>


  </array>

  <key>PayloadDescription</key>

  <string>スクリプトメニューの設定です</string>

  <key>PayloadDisplayName</key>

  <string>com.apple.scriptmenu</string>

  <key>ConsentText</key>

  <dict>

    <key>default</key>

    <string>日本語の詳しい解説例:スクリプトメニューを有効にします</string>

    <key>jp</key>

    <string>日本語の詳しい解説例:スクリプトメニューを有効にします</string>

  </dict>

  <key>PayloadIdentifier</key>

  <string>com.apple.scriptmenu.671145E3-CFD4-4A20-A381-366D53D9447F</string>

  <key>PayloadOrganization</key>

  <string>com.cocolog-nifty.quicktimer</string>

  <key>PayloadRemovalDisallowed</key>

  <false/>

  <key>PayloadScope</key>

  <string>User</string>

  <key>PayloadType</key>

  <string>Configuration</string>

  <key>PayloadUUID</key>

  <string>671145E3-CFD4-4A20-A381-366D53D9447F</string>

  <key>PayloadVersion</key>

  <integer>20221027</integer>

  <key>TargetDeviceType</key>

  <integer>5</integer>

</dict>

</plist>


|

[TOOL]スクリプトを開く

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

####スクリプトのUTI
set listUTI to {"com.apple.applescript.script", "com.apple.applescript.text"}
###サブフォルダ名
set strDirName to "Scripts" as text

set aliasPathToMe to path to me as alias
log aliasPathToMe
tell application "Finder"
set aliasContainer to container of aliasPathToMe as alias
set aliasScriptDir to folder strDirName of folder aliasContainer as alias
end tell
tell application "Finder"
set listScripts to name of every item of aliasScriptDir as list
end tell
try
set objResponse to (choose from list listScripts with title "選んでください" with prompt "開くスクリプトを選んでください" default items (item 1 of listScripts) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
log "エラーしました"
return
end try
if objResponse is false then
log "キャンセルしました"
return
end if

set strResponse to (objResponse) as text
log strResponse
tell application "Finder"
set aliasFilePath to file strResponse of folder aliasScriptDir
end tell

try
tell application "Script Editor"
launch
activate
open aliasFilePath
end tell
on error
tell application "Finder"
set aliasDefaultLocation to container of (path to me) as alias
end tell
set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
tell application "Script Editor"
launch
activate
open aliasFilePath
end tell
end try

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom