|
|
#1 |
|
Triple-A Player
Join Date: May 2003
Location: homeless
Posts: 111
|
Applescript strcmp?
i never made something in applescript, but i wanted to make a applescript folder action for the desktop.
the script would automatically convert the "screencapture's" ouput (Picture 1.pdf, Picture 2.pdf, etc) to PNG's. something similiar to the Duplicate as PNG action script. but i dont know how to check if the filename has the format of "Picutre #.pdf", anyone knows? |
|
|
|
|
|
#2 |
|
Major Leaguer
Join Date: Feb 2004
Posts: 278
|
You could manually dig through the string yourself, using constructs like "characters 1 through n of thestring". Here is a reference for some of those kind of commands.
A more powerful and probably easier solution is to use a regex scripting addition, like this one. You might also try something from the terminal. "screencapture" is the command-line interface, and "screencapture -c" will put the result on the clipboard. You could then use "pbpaste" and pipe that pdf to an image conversion program to get png output. |
|
|
|
|
|
#3 |
|
Triple-A Player
Join Date: May 2003
Location: homeless
Posts: 111
|
thanks, i will read that documentation tomorrow
![]() the reason i want it to do it this way is that i have bound the builtin screencapture command to a different key, namely to apple+option+F12 on my powerbook (more accessible and memorizeable than the default one, apple+shift+3 )copy pasting it sounds overkill, and not very efficient ![]() but ofcourse the best thing would be if Apple made an option to specify the screencapture output. I dont get it why they didnt, really. Maybe we should go bug Apple for this feature, who's with me?
|
|
|
|
|
|
#4 |
|
Triple-A Player
Join Date: May 2003
Posts: 150
|
You could use the folder action script that I posted to this thread and just replace every instance of JPEG and jpg with png. This should do it:
Code:
on adding folder items to this_folder after receiving these_items repeat with an_item in these_items tell application "Finder" set file_name to name of an_item set file_ext to name extension of an_item if file_name starts with "Picture" and file_ext is "pdf" then set png_path to my getSafeName() tell me to convertToPNG(an_item, png_path) end if end tell end repeat end adding folder items to on getSafeName() set desk_path to (path to desktop as Unicode text) try alias (desk_path & "Picture 1.png") set i to 0 repeat set i to i + 1 set path_to_check to (desk_path & "Picture " & i & ".png") try alias path_to_check on error set png_path to path_to_check exit repeat end try end repeat on error set png_path to (desk_path & "Picture 1.png") end try return png_path end getSafeName on convertToPNG(pdf_file, png_path) tell application "Image Events" launch set image_ref to open pdf_file save image_ref in png_path as PNG with icon close image_ref delete pdf_file end tell end convertToPNG |
|
|
|
|
|
#5 |
|
Triple-A Player
Join Date: May 2003
Location: homeless
Posts: 111
|
Cool, now i dont have to figure out applescript
![]() The script works like a charm, thanks mate!
|
|
|
|
|
|
#6 |
|
Triple-A Player
Join Date: May 2003
Posts: 150
|
You're welcome. I'm glad it did the job.
|
|
|
|
|
|
#7 | |||||||||||||||||||||||
|
Prospect
Join Date: Aug 2004
Posts: 3
|
Here's another version that lets you choose the file format to convert it to: Code:
on adding folder items to this_folder after receiving these_items
repeat with an_item in these_items
tell application "Finder"
set file_name to name of an_item
set file_ext to name extension of an_item
set desk_path to (this_folder as string)
set pdf_size to (size of file an_item as integer)
repeat until pdf_size > 0
delay 1
set pdf_size to (size of file an_item as integer)
end repeat
if file_name starts with "Picture" and file_ext is "PDF" then
set format_return to display dialog "Select output format." buttons {".pct", ".jpg", ".pdf"} default button ".pdf"
set output_format to button returned of format_return
set AppleScript's text item delimiters to "."
set base_filename to the first text item of file_name
set img_path to desk_path & base_filename & output_format
tell me to convert(an_item, img_path, output_format)
end if
end tell
end repeat
end adding folder items to
on convert(img_file, img_path, output_format)
tell application "Image Events"
launch
set image_ref to open img_file
if output_format is ".jpg" then
save image_ref in img_path as JPEG with icon
delete img_file
else if output_format is ".pct" then
save image_ref in img_path as PICT with icon
delete img_file
end if
close image_ref
end tell
end convert
|
|||||||||||||||||||||||
|
|
|
![]() |
|
|