File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -613,14 +613,18 @@ impl IconConversion {
613613 // - https://github.com/mklement0/fileicon/blob/9c41a44fac462f66a1194e223aa26e4c3b9b5ae3/bin/fileicon#L268-L276
614614 // - https://github.com/mklement0/fileicon/issues/32#issuecomment-1074124748
615615 // - https://apple.stackexchange.com/a/161984
616+ //
617+ // In theory, we could try to call the Cocoa framework diretcly through
618+ // bridging or linking. However, AppleScript is more likely to be
619+ // portable across macOS versions.
616620 let stdin = format ! ( "use framework \" Cocoa\"
617621
618622 set sourcePath to \" {}\"
619623 set destPath to \" {}\"
620624
621625 set imageData to (current application's NSImage's alloc()'s initWithContentsOfFile:sourcePath)
622626 (current application's NSWorkspace's sharedWorkspace()'s setIcon:imageData forFile:destPath options:2)" ,
623- icns_path. to_string_lossy( ) , target_path. to_string_lossy( )
627+ escape_path_for_applescript ( & icns_path. to_string_lossy( ) ) , escape_path_for_applescript ( & target_path. to_string_lossy( ) )
624628 ) ;
625629
626630 let args = CommandArgs :: new ( ) ;
@@ -716,3 +720,8 @@ impl IconConversion {
716720 Ok ( ( ) )
717721 }
718722}
723+
724+ pub fn escape_path_for_applescript ( path : & str ) -> String {
725+ // Newlines don't need to be escaped.
726+ path. replace ( '\\' , "\\ \\ " ) . replace ( '\"' , "\\ \" " )
727+ }
You can’t perform that action at this time.
0 commit comments