|
-- Author: Mathijs Kadijk |
|
-- License: MIT License |
|
-- From: https://gist.github.com/mac-cain13/91d4641240ea9cb3394d |
|
|
|
on adding folder items to this_folder after receiving added_items |
|
|
|
set resolutions to {{suffix:"@4x", folder:"xxxhdpi"}, {suffix:"@3x", folder:"xxhdpi"}, {suffix:"@2x", folder:"xhdpi"}, {suffix:"@1,5x", folder:"hdpi"}, {suffix:"@1.5x", folder:"hdpi"}, {suffix:"@1x", folder:"mdpi"}} |
|
|
|
repeat with the_item in the added_items |
|
try |
|
tell application "Finder" |
|
set the item_extension to the name extension of the_item |
|
set the item_name to the name of the_item |
|
set this_folder_path to POSIX path of this_folder |
|
end tell |
|
|
|
repeat with resolution in the resolutions |
|
set ending to suffix of resolution & "." & item_extension |
|
if item_name ends with ending then |
|
set destination_folder_path to this_folder_path & "res/drawable-" & folder of resolution |
|
set destination_filename to trim_line(item_name, ending, 1) & "." & item_extension |
|
set destination_path to destination_folder_path & "/" & destination_filename |
|
do shell script "mv " & quoted form of POSIX path of the_item & " " & quoted form of destination_path |
|
end if |
|
end repeat |
|
|
|
end try |
|
end repeat |
|
end adding folder items to |
|
|
|
---- |
|
|
|
on trim_line(this_text, trim_chars, trim_indicator) |
|
-- 0 = beginning, 1 = end, 2 = both |
|
set x to the length of the trim_chars |
|
-- TRIM BEGINNING |
|
if the trim_indicator is in {0, 2} then |
|
repeat while this_text begins with the trim_chars |
|
try |
|
set this_text to characters (x + 1) thru -1 of this_text as string |
|
on error |
|
-- the text contains nothing but the trim characters |
|
return "" |
|
end try |
|
end repeat |
|
end if |
|
-- TRIM ENDING |
|
if the trim_indicator is in {1, 2} then |
|
repeat while this_text ends with the trim_chars |
|
try |
|
set this_text to characters 1 thru -(x + 1) of this_text as string |
|
on error |
|
-- the text contains nothing but the trim characters |
|
return "" |
|
end try |
|
end repeat |
|
end if |
|
return this_text |
|
end trim_line |
Hey @mac-cain13 !!
Could you look into exporting @1x assets without the actual suffix? Sketch isn't doing that by default, so it could save me lots of time :D