20260413

WEBページ上のソースの安全性をChatGPTに評価してもらう(クイックアクション)

WEBページ上のソースの安全性をChatGPTに評価してもらう(クイックアクション)

ダウンロードはこちら
NOTE記事一覧ですnote.com

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

Send_Code.scpt.scpt
ソース
001#!/usr/bin/osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
004(*
005オートメーター用
006選択部分のコマンドを
007OPENAIに質問します
008
009非ログイン状態だとURLを送信した時点でブラウザが実行されます
010ログイン済みだと編集可能な状態で停止します
011
012
013v1 初回作成
014
015com.cocolog-nifty.quicktimer.icefloe *)
016----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
017use AppleScript version "2.8"
018use framework "Foundation"
019use framework "AppKit"
020use scripting additions
021property refMe : a reference to current application
022
023on run {strSelectedString}
024   #テスト用
025   #on run
026   #set strSelectedString to ("/bin/echo \"SOME\"") as text
027   set strSelectedString to strSelectedString as text
028   set boolDone to (open strSelectedString) as boolean
029   return boolDone as boolean
030end run
031
032on open strSelectedString
033   #テキスト形式確定させて
034   set strSelectedString to strSelectedString as text
035   ##############################
036   #   改行だけ置換しておくCR→LF
037   set strLF to ("" & linefeed & "") as text
038   set strCR to ("" & return & "") as text
039   
040   set strDelim to AppleScript's text item delimiters
041   set AppleScript's text item delimiters to strCR
042   set listReturnText to every text item of strSelectedString
043   set AppleScript's text item delimiters to strLF
044   set strReturn to listReturnText as text
045   set AppleScript's text item delimiters to strDelim
046   
047   #URLを作成
048   set ocidOpenURL to doMakeURL(strReturn)
049   set ocidURLstring to ocidOpenURL's absoluteString()
050   log ocidURLstring as text
051   #URLを開く
052   set boolDone to doOpenURL(ocidOpenURL) as boolean
053   return boolDone as boolean
054end open
055
056
057##############################
058#URLを開く(デフォルトアプリケーションで)
059on doOpenURL(ocidOpenURL)
060   set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
061   
062   (*
063   #アプリケーションを指定する場合
064
065   #   set ocidAppURL to appSharedWorkspace's URLForApplicationWithBundleIdentifier:("com.apple.Safari")
066   #   set ocidAppURL to appSharedWorkspace's URLForApplicationWithBundleIdentifier:("org.mozilla.firefox")
067   #   set ocidAppURL to appSharedWorkspace's URLForApplicationWithBundleIdentifier:("com.google.Chrome")
068   set ocidAppURL to appSharedWorkspace's URLForApplicationWithBundleIdentifier:("com.microsoft.edgemac")
069   set ocidConfig to refMe's NSWorkspaceOpenConfiguration's configuration()
070   (ocidConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
071   ocidConfig's setHides:(refMe's NSNumber's numberWithBool:false)
072   set ocidOpenURLsArray to refMe's NSMutableArray's alloc()'s init()
073   (ocidOpenURLsArray's addObject:(ocidOpenURL))
074   (appSharedWorkspace's openURLs:(ocidOpenURLsArray) withApplicationAtURL:(ocidAppURL) configuration:(ocidConfig) completionHandler:(missing value))
075   return true
076      *)
077   #デフォルトのブラウザで開く場合
078   set boolDone to appSharedWorkspace's openURL:(ocidOpenURL)
079   return boolDone as boolean
080   
081end doOpenURL
082
083
084##############################
085#OPENするURLの生成
086on doMakeURL(strReturn)
087   set strLF to ("" & linefeed & "") as text
088   #   クエリー部分生成
089   set strBase to ("このコードの安全性を評価してください。" & strLF & "- 何をするコマンドか?" & strLF & "- 危険性の有無と安全性の評価" & strLF & "- 初心者が実行してよいかを★5で評価してください" & strLF & "- コードはそのまま実行してよいか?" & strLF & "コード:" & strLF & "") as text
090   set strQuery to ("" & strBase & strReturn & "") as text
091   #文末改行は削除する
092   set strLF to ("" & linefeed & "") as text
093   set ocidQueryString to refMe's NSMutableString's stringWithString:(strQuery)
094   set boolHasSuf to (ocidQueryString's hasSuffix:(strLF))
095   if boolHasSuf is true then
096      set ocidCharSet to refMe's NSCharacterSet's newlineCharacterSet()
097      set ocidQueryString to ocidQueryString's stringByTrimmingCharactersInSet:(ocidCharSet)
098   end if
099   
100   #URLコンポーネント初期化
101   set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
102   #スキーム を追加
103   ocidURLComponents's setScheme:("https")
104   #ホストを追加
105   ocidURLComponents's setHost:("chat.openai.com")
106   #パスを追加
107   ocidURLComponents's setPath:("/")
108   #クエリー部
109   set ocidQueryItems to refMe's NSMutableArray's alloc()'s init()
110   ocidQueryItems's addObject:(refMe's NSURLQueryItem's alloc()'s initWithName:("q") value:(ocidQueryString))
111   #クエリーをセットする
112   ocidURLComponents's setQueryItems:(ocidQueryItems)
113   #URLに戻して テキストにしておく
114   set ocidOpenURL to ocidURLComponents's |URL|()
115   
116   return ocidOpenURL
117end doMakeURL
AppleScriptで生成しました