20260531

ファイルやフォルダのロック設定・解除AS

ファイルやフォルダのロック設定・解除AS

NOTE記事一覧ですnote.com
 

【Safari・FireFox用Script Editorで開く】 |

ロック設定・解除AS.scpt.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
004(*
005
006クラッシックなAS記法で
007ファイル・フォルダのロックとロックの解除
008
009
010
011com.cocolog-nifty.quicktimer.icefloe *)
012----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
013use AppleScript version "2.8"
014use scripting additions
015
016
017########################
018# RUN
019#   on run {listAliasFilePath}
020
021on run
022   
023   ########################
024   #ダイアログ
025   set strMsg to ("ファイル 選択") as text
026   set strPrompt to ("ファイル を選択してください" & return & "複数選択可") as text
027   set aliasDesktopDirPath to (path to desktop from user domain) as alias
028   set listUTI to {"public.item"} as list
029   try
030      tell application "SystemUIServer"
031         activate
032         set listAliasFilePath to (choose file strMsg with prompt strPrompt default location aliasDesktopDirPath of type listUTI with invisibles and multiple selections allowed without showing package contents) as list
033         
034         
035         #   set listAliasFilePath to (choose folder strMsg with prompt strPrompt default location aliasDesktopDirPath with invisibles, multiple selections allowed and showing package contents) as list
036         
037      end tell
038   on error strErrMes number numErrNo
039      log strErrMes & numErrNo
040      return false
041   end try
042   if listAliasFilePath is {} then
043      return false
044   end if
045   
046   
047   set boolDone to (open listAliasFilePath)
048   return boolDone
049end run
050
051########################
052# OPEN
053on open listAliasFilePath
054   
055   
056   repeat with itemAliasFilePath in listAliasFilePath
057      set aliasItemFilePath to itemAliasFilePath as alias
058      set recordInfoFor to (info for aliasItemFilePath) as record
059      set boolIsAlias to (alias of recordInfoFor) as boolean
060      if boolIsAlias is false then
061         set boolIsPKG to (package folder of recordInfoFor) as boolean
062         if boolIsPKG is false then
063            set boolIsDir to (folder of recordInfoFor) as boolean
064            if boolIsDir is false then
065               set boolDone to doFileLock(aliasItemFilePath)
066            else if boolIsDir is true then
067               set boolDone to doFolderLock(aliasItemFilePath)
068            end if
069         else if boolIsPKG is true then
070            set strExt to (name extension of recordInfoFor) as text
071            if strExt is "app" then
072               set boolDone to doAppLock(aliasItemFilePath)
073            else if strExt is "pkg" then
074               set boolDone to doPkgLock(aliasItemFilePath)
075            else
076               set boolDone to doFileLock(aliasItemFilePath)
077            end if
078         end if
079      else if boolIsAlias is true then
080         set boolDone to doAliasLock(aliasItemFilePath)
081      end if
082   end repeat
083   
084   
085   return boolDone
086end open
087
088########################
089#エイリアス
090to doPkgLock(argAliasFilePath)
091   set aliasFilePath to argAliasFilePath as alias
092   tell application "Finder"
093      tell file aliasFilePath
094         set boolLock to (its locked) as boolean
095      end tell
096   end tell
097   if boolLock is true then
098      tell application "Finder"
099         tell file aliasFilePath
100            set (its locked) to false as boolean
101         end tell
102      end tell
103      return false
104   else if boolLock is false then
105      tell application "Finder"
106         tell file aliasFilePath
107            set (its locked) to true as boolean
108         end tell
109      end tell
110      return true
111   end if
112   
113end doPkgLock
114
115
116########################
117#エイリアス
118to doAppLock(argAliasFilePath)
119   set aliasFilePath to argAliasFilePath as alias
120   tell application "Finder"
121      tell file aliasFilePath
122         set boolLock to (its locked) as boolean
123      end tell
124   end tell
125   if boolLock is true then
126      tell application "Finder"
127         tell application file aliasFilePath
128            set (its locked) to false as boolean
129         end tell
130      end tell
131      return false
132   else if boolLock is false then
133      tell application "Finder"
134         tell application file aliasFilePath
135            set (its locked) to true as boolean
136         end tell
137      end tell
138      return true
139   end if
140   
141end doAppLock
142
143########################
144#エイリアス
145to doAliasLock(argAliasFilePath)
146   set aliasFilePath to argAliasFilePath as alias
147   tell application "Finder"
148      tell alias file aliasFilePath
149         set boolLock to (its locked) as boolean
150      end tell
151   end tell
152   if boolLock is true then
153      tell application "Finder"
154         tell alias file aliasFilePath
155            set (its locked) to false as boolean
156         end tell
157      end tell
158      return false
159   else if boolLock is false then
160      tell application "Finder"
161         tell alias file aliasFilePath
162            set (its locked) to true as boolean
163         end tell
164      end tell
165      return true
166   end if
167   
168end doAliasLock
169
170########################
171#フォルダ
172to doFolderLock(argAliasFilePath)
173   set aliasFilePath to argAliasFilePath as alias
174   tell application "Finder"
175      tell folder aliasFilePath
176         set boolLock to (its locked) as boolean
177      end tell
178   end tell
179   if boolLock is true then
180      tell application "Finder"
181         tell folder aliasFilePath
182            set (its locked) to false as boolean
183         end tell
184      end tell
185      return false
186   else if boolLock is false then
187      tell application "Finder"
188         tell folder aliasFilePath
189            set (its locked) to true as boolean
190         end tell
191      end tell
192      return true
193   end if
194   
195end doFolderLock
196
197
198
199########################
200#ファイル
201to doFileLock(argAliasFilePath)
202   set aliasFilePath to argAliasFilePath as alias
203   tell application "Finder"
204      tell file aliasFilePath
205         set boolLock to (its locked) as boolean
206      end tell
207   end tell
208   if boolLock is true then
209      tell application "Finder"
210         tell file aliasFilePath
211            set (its locked) to false as boolean
212         end tell
213      end tell
214      return false
215   else if boolLock is false then
216      tell application "Finder"
217         tell file aliasFilePath
218            set (its locked) to true as boolean
219         end tell
220      end tell
221      return true
222   end if
223   
224end doFileLock
225
AppleScriptで生成しました