Changing icon size in Applescript "choose file" window? - applescript

Is there a way to change the icon size in a "choose file" preview window? I'd like to make my preview thumbnails larger.
Here's the code I'm using. Pretty basic:
set theFile to (choose file of screenFolder with prompt "Select a file to read:" of type {"JPG"})
Thanks!

As far as I know, you can't change the size of the preview window (I apologize for any inconvenience).
Note
Your code won't compile. I'm assuming you want screenFolder to automatically be opened. If that is true, then use the default location property, which automatically navigates to the desired folder. Your new code should look something like this...
set theFile to (choose file with prompt "Select an image to read:" default location screenFolder of type {"JPG"})

Related

Applescript to Control Photoshop Save Dialog Box

How are you?
I've created an applescript automation to save files in .JPG while the Save Dialog Box is open. (So I can control the name of the saved files)
Is there a way to control the Save Dialog Box of Photoshop?
What I want to happen is: Upon appearing of save dialog box
-Command + a will happen (to select all characters)
-Press delete (to delete all characters selected)
-Delay 8 seconds = Enough time for me write my own file name.
-Automation will press return to save the file under my own written file name.
I tried reading Photoshop's dictionary at Script editor but found no results for Controlling Photoshop's save dialog box.
I tried doing system events to do command a + press delete + delay 8
seconds and pressing return but that event only happens after the save
dialog box disappears instead of doing that on the actual save dialog
box.
My Photoshop is: CS6 Extended
Os: El Capitan
Thank you very much.
You should avoid using GUI scripting : each time Adobe (or Apple) will change the graphic display of the 'save as' dialog box, your script may no longer work.
Instead, use a 2 step approach : 1) get the false name and path using a standard 'choose file name' and then use this file to save using 'save' command in Photoshop. This script assume there is a current open document.
Please update 'Adobe Photoshop CS3' with your version (mine is a bit old, but good enough to test !).
Also, the default folder could be adjusted for your needs (here = Desktop).
tell application "Adobe Photoshop CS3"
set docRef to the current document
set docName to name of docRef -- current name will be use as default new name
set file2save to ((choose file name default location (path to desktop) default name docName) as string)
save docRef in file file2save as JPEG appending lowercase extension with copying
end tell
Note 1: you can improve that script by checking the extension typed in file2save variable, and, if missing, the script can add the correct extension (i.e. 'jpg').
Note 2: Adobe made some changes in 'open ' command between version CS3 and CS6. I hope these changes do not affect the 'save' command.
This is a code to what you specified also it includes open the save box:
tell application "Adobe Photoshop CS6"
activate
tell application "System Events"
keystroke "s" using {command down, shift down}
delay 1
keystroke "a" using {command down}
delay 0.1
key code 51
delay 8
keystroke return
end tell
end tell

How to remove alpha from bulk images with AppleScript

I have a bulk amount of images, of which i need to remove alpha from each. This is doable from Preview application, but the sheer amount of times i would need to repeat that is way too time consuming.
I have heard about AppleScript and made some feeble attempts at automating the process, currently to no avail.
i am using something like this and then starting a repeat, but it only allows me to loop through one direct folder (also i'm having troubles with menu bar items)
set fl to files of folder POSIX file "/Users/user/Documents/" as alias list
But i have multiple folders within folders which i wish to change an amount of images. the folder structure is like this:
Users/user/folder/ImagesRoot/
in inside ImagesRoot are 3 folders and one txt file. I want to specifically select 2 of the folders called "Icons" and "Screenshots". In "Icons" is 5 images. However "Screenshots" contains 3 subfolders, each with their own 5 images. (can be referred to as "Screensub 1,2,3")
Once receiving the list of images inside such folder, the process would be something like
tell application "Preview"
open the image file
open the file menu
open export...
untick alpha
press save
press replace
close window
end tell
Loop to next one
when looped through all in Icons folder, do all 5 images of each subfolder of screenshot folder
I am told that AppleScript is a good way to do this, but also that bash is a possibility?
However, i have 2% experience with applescript and maybe 4% of bash, and don't know how to approach it.
Any advice or help would be greatly appreciated.
Thanks
As far as I can tell, Preview doesn’t have the ability to change the alpha of a document, even if you enable AppleScripting. In an application that does support it, such as GraphicConverter, this is a fairly simple task:
on open imageFile
tell application "GraphicConverter 9"
open imageFile
tell window 1
set alpha to false
end tell
--save image as needed
end tell
end open
You may find it easier to use Automator. The combination of Get Folder Contents with Repeat for each subfolder found and Alpha Channel set to Remove may be all you need. If you need to exclude some files, Filter Finder Items would do it.
If you want to use Preview, however, you may be able to use System Events. Something like:
on open imageFile
tell application "Preview"
open imageFile
activate
set filename to name of window 1
tell application "System Events"
tell process "Preview"
click menu item "Export…" of menu "File" of menu bar 1
tell sheet 1 of window 1
--rename file
set value of text field 1 to filename & " Alpha Removed"
--uncheck alpha channel
tell checkbox 1 of group 1
click
end tell
--save
click button "Save"
end tell
end tell
end tell
end tell
end open
If you choose the assistive access route, you may find Apple’s help on signing applications useful: http://support.apple.com/kb/HT5914

AppleScript to get name of single selected file in finder

I want to get the name of the currently in the finder window selected file. I'm working under OS X 10.9.2.
Here's my code:
display dialog "test"
tell application "Finder"
set theItems to selection
display dialog number of theItems
repeat with itemRef in theItems
display dialog name of itemRef
end repeat
end tell
In the Finder I selected only one mp3 file.
If I run the script then the dialogbox with "test" and the dialogbox with "1" is displayed correctly. But then I got the error message that the file cannot be converted into a type string.
I hope you can help me to fix this bug and I thank you in advance for your reply!
The name property of a file is already a text (or string) type. You are not properly parenthesizing the dialog statement.
display dialog (get name of itemRef)
file cannot be converted into a type string.
Then convert it to a string.
display dialog (name of itemRef) as string
I'd suggest you to use log instead of display dialog for debugging purpose.
For instance, log name of itemRef will return (in your "Events" and "Replies" window):
(name of document file 123.jpg of folder Desktop of
folder Saturnix of folder Users of startup disk)
As you can see, this is much more complex than a simple string of test (like "123.jpg"). This is telling you that name of itemRef is not returning the actual name of the file itemRef but a reference to that name. Luckily enough, calling as string on that reference will return us the actual name of the file.

How can I tell Finder to make a new Finder window with properties?

I have the following snippet in a larger script:
--I think this should work…
--make new Finder window with properties {target:theWallpaperPosixFile}
set theWindow to make new Finder window
set target of theWindow to theWallpaperPosixFile
Why does the commented out line not work when I believe it should be functionally identical to the bottom line?
EDIT: To be clear, the code works as is. I'm missing something about with properties. My understanding from this as well as many other sites and the Finder Dictionary is that the 2 liner should be equivalent to the one liner. But it's not. It just pops open a new Finder window with no target.
So my question is specifically how to use with properties, not 'how to make it work'.
Try:
set wallpaperPaths to {POSIX path of (path to documents folder)} -- Example
repeat with wallpaperPath in wallpaperPaths
set theWallpaperPosixFile to POSIX file (contents of wallpaperPath) as alias
tell application "Finder" to set theWindow to make new Finder window to theWallpaperPosixFile
end repeat
EDIT
Look in the dictionary for Make in the Standard Suite:

AppleScript "Save As" HTML in TextEdit

I want AppleScript to loop through a set of of RTF files in folder and save them as HTML files.
This is my simple code so far. The XXXX is where I'm struggling:
tell application "Finder"
set source_folder to choose folder
set aList to every file in source_folder
repeat with i from 1 to number of items in aList
tell application "TextEdit"
set aFile to (item i of aList)
save as aFile XXXXXXXXX
end tell
end repeat
end tell
I'm really new to this... any help much appreciated.
You don't need TextEdit for this. There is a command line program textutil which will do the job without all the opening and saving stuff required with TextEdit. We can fix your TextEdit script (it has a few errors) but try this first and let us know if it does the job for you. The html files will have the same name but with the html extension and will be located in source_folder. The ouput path can be changed in the code by using the "-output" switch of textutil. See "man textutil" if you want to look at everything it can do.
And a general question... what is a RTD file? Do you mean rtf or rtfd? Textutil will work with rtf/rtfd but not rtd, so I hope that isn't really your file type.
set source_folder to choose folder with prompt "Choose a source folder."
set output_folder to choose folder with prompt "Choose an output folder."
tell application "Finder"
set theFiles to (files of entire contents of source_folder) as alias list
end tell
repeat with aFile in theFiles
tell application "Finder"
set fileName to name of aFile
set fileExt to name extension of aFile
end tell
set outputPath to (output_folder as text) & text 1 thru -((count of fileExt) + 1) of fileName & "html"
do shell script "/usr/bin/textutil -convert html -output " & quoted form of POSIX path of outputPath & space & quoted form of POSIX path of aFile
end repeat
You mention you are new to applescript, so I'll give you some general pointers you should keep in mind when writing applescript code.
Avoid putting tell blocks of code inside each other. You have tell app TextEdit inside tell app Finder. That's bad. Doing this is a source of many conflicts because you are basically telling the Finder to tell TextEdit to do something. That's not good because commands can get confused and it's really hard to debug these kinds of issues. So keep your tell blocks separate.
Avoid telling an application to perform a command that is not in its applescript dictionary. You should only tell an application to do commands that it knows and an application only knows about the commands in its dictionary. So for example, you are telling the Finder to "choose folder". The Finder does not know that command. That's an applescript command. So doing as you have done is another possible source of errors. In this case that's a simple command and it will work but in general avoid doing this.
Regarding the Finder, you should avoid using it too much. The Finder is a major program on your computer and is often busy doing computer related stuff. As such it's best to only use it when necessary. As an example you can see in my code that I removed the "choose folder" and the repeat loop from the Finder. I purposely appended "as alias list" to the end of the Finder command to make the list of files usable outside of the Finder tell block of code. Of course use the Finder if needed but it's best to not use it if you don't need it.
Use the applescript dictionary of your applications. As mentioned above, the dictionary lists all of the terms and the syntax that an application understands (granted the dictionaries are difficult to understand but you will get better at it the more you use them). Under the file menu of AppleScript Editor choose "Open dictionary" and a list of all the applications that understand applescript is shown. Choose an application from that to see its dictionary. So for example, you are trying to figure out TextEdit's "save as" command. You can usually get good direction from the dictionary so you should take a look at that. Use the search field to search!
So I hope that helps! Good luck.

Resources