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

|

その他のカテゴリー

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