Since allowedFileTypes is removed on macOS 12.0, you need workaround to replace the feature.
๐ฉScreenshot main:
qiita.rb
func ExecIBScreenshot() { //<*๐Screenshot*>
let wShot:NSImage? = macOS.CallGetScreenshot(appName, pPercent:1, pInverse:false) //๐Get screenshot.
if wShot == nil { return } //
else { } //
let wcgi:CGImage = wShot!.cgImage(forProposedRect: nil, context: nil, hints: nil)!//Convert to CGImage.
let wRep:NSBitmapImageRep = NSBitmapImageRep(cgImage: wcgi) //
let wData:NSData = wRep.representation(using: .png, properties: [:])! as NSData //
var wName:String = "" //
if zScreenFolder == "" { //
zScreenName = "screenshotMMA" //filename
wName = zScreenName //screenshotMMA for the alert.
} else { //
zScreenNum += 1 //
let wNum:String = Call.PickupLastWords(String(1000 + zScreenNum), pString: "999")//001, 002, ... 999
wName = zScreenName + wNum //screenshotMMA999
} //
let wFolder:URL = URL(fileURLWithPath:NSHomeDirectory()+"/Desktop") //Save on the desktop.
let wX = macOS.SavePanelScreen(["png"], pMsg:cm.rcMSG[LT.msg17], //20220318
pDirURL:wFolder, pCreateDir:true, pFName:wName+".png") //Save panel
let wA = Call.GetFileInfo(wX.rURL, pExtentionArray: [], pSyspathArray: [])//Get file info.
zScreenType = "." + wA.rExtention //
let wNew:String = Call.RemoveLastWords(wA.rName, pString: zScreenType) //Remove the extention.
if wNew == wName { //
} else { //
zScreenName = wNew //Replace it to userโs one.
} //
zScreenFolder = Call.RemoveLastWords((wX.rURL).path, pString: zScreenName + zScreenType)//folder path
Call.WriteDatafile(wX.rURL, pData: wData) //Write the screenshot.
}//๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ๐
ฟ๏ธ//
๐ฉSavePanel for Screenshot:
qiita.rb
func SavePanelScreen(_ pFType:[String], pMsg:String, pDirURL:URL?, //๐20220318 (M19)<*NSSavePanel*>
pCreateDir:Bool, pFName:String)-> (rURL:URL, rState:String) { //๐โ nil: Cancelled โกOK: rURL is OK.
let wBool:Bool = false //๐
while wBool == false { //๐
let wSave = NSSavePanel() //๐
wSave.nameFieldStringValue = pFName //๐
// if pFType.count > 0 { wSave.allowedFileTypes = pFType } //๐Set Extention. โDesperated on macOS 12.0
wSave.allowsOtherFileTypes = false //๐Do not allow other extentions.
wSave.message = pMsg //๐Messaga for the panel.
wSave.directoryURL = pDirURL //๐Folder name for the panel.
wSave.canCreateDirectories = pCreateDir //๐A user can create a new folder.
wSave.treatsFilePackagesAsDirectories = false //๐
let wModal = wSave.runModal() //๐
if wModal.rawValue == NSApplication.ModalResponse.cancel.rawValue {//๐
return (wSave.url!, rrNG) //๐โป๏ธreturnโป๏ธ Canceled.
// } else { return (wSave.url!, "") } //๐โป๏ธreturnโป๏ธ Normal end โDesperated on macOS 12.0
} else { //๐20220318
let wPath:String = wSave.url!.path + "" //๐20220318<โ-Use the file name + extention as is.
return (URL(fileURLWithPath: wPath), "") //๐20220318 โป๏ธreturnโป๏ธ Normal
} //๐
} //๐
}//-----------------------------------------------------------------//๐
๐ฉUsual SavePanel:
qiita.rb
func OpenPanel(_ pFType:[String], pMulti:Bool, pDir:Bool, //๐(M20)<*NSOpenPanel*>
pFile:Bool, pCreateDir:Bool)-> [URL] { //๐โ nil: Cancelled โกOK: rURL is OK.
let wBool:Bool = false //๐
while wBool == false { //๐
let NSOpen = NSOpenPanel() //๐allowedContentTypes
// if pFType.count > 0 { NSOpen.allowedFileTypes = pFType } //๐20220318 Set Extention. โDesperated on macOS 12.0
NSOpen.allowsMultipleSelection = pMulti //๐Multiple selection
NSOpen.canChooseDirectories = pDir //๐Folder
NSOpen.canChooseFiles = pFile //๐File
NSOpen.canCreateDirectories = pCreateDir //๐Create a new folder
NSOpen.treatsFilePackagesAsDirectories = false //๐
let wModal = NSOpen.runModal() //๐
if wModal.rawValue == NSApplication.ModalResponse.cancel.rawValue {//๐
return [] //๐โป๏ธreturnโป๏ธ Canceled: []
} else if NSOpen.urls.count > 0 { //๐
var wURL:[URL] = [] //๐20220318
var wFType:[String] = [] //๐20220318
for ftype in pFType { //๐20220318 Convert every extention to โ.โ + extention.
wFType.append("."+ftype) //๐20220318
} //๐20220318
for url in NSOpen.urls { //๐20220318 The filepath has one of extentions that are allowed?
let wA = Call.GetFileType(url, pTypeArray: pFType) //๐20220318
if wA != "" { //๐20220318 <โ-Yes
wURL.append(url) //๐20220318 Save the URL
} else { } //๐20220318 <โ-No
} //๐20220318
return wURL //๐โป๏ธreturnโป๏ธ Normal end
} //๐
} //๐
}//-----------------------------------------------------------------//๐