I have two versions of Illustrator installed, Adobe Illustrator 2020 and Adobe Illustrator CC 2019. How do I ensure from Applescript that the Adobe Illustrator CC 2019 is picked?
For that, i have did the following applescript coding, but the applescript automatically change the application name.
set theResult to every paragraph of (do shell script "mdfind 'kMDItemContentTypeTree == \"com.apple.application\"c' | sort")
set systemApps to {}
set applicationsApps to {}
set Version2019 to "" as string
set Version2020 to "" as string
repeat with i from 1 to number of items in theResult
set end of systemApps to item i of theResult
if item i of theResult contains "Adobe Illustrator CC 2019" then
set end of applicationsApps to item i of theResult
set Version2019 to "true" as string
exit repeat
end if
end repeat
repeat with i from 1 to number of items in theResult
set end of systemApps to item i of theResult
if item i of theResult contains "Adobe Illustrator 2020" then
set end of applicationsApps to item i of theResult
set Version2020 to "true" as string
exit repeat
end if
end repeat
--display dialog (Version2019)
tell application "Finder"
if (Version2019 contains "true" and Version2020 contains "true") then
--display dialog "hey! " & theUser & return & return & "Adobe Illustrator 2019 and Adobe Illustrator 2020 available in this Mac" buttons {"Ok"}
set questionStudio to display dialog "hey! " & return & return & "Adobe Illustrator 2019 and Adobe Illustrator 2020 available in this Mac." & return & return & "Please select Version:" buttons {"Adobe Illustrator CC 2019", "Adobe Illustrator 2020", "Cancel"}
set answerStudio to button returned of questionStudio
if answerStudio contains "Adobe Illustrator 2020" then
tell application "/Applications/Adobe Illustrator 2020/Adobe Illustrator.app"
if it is not running then launch
end tell
it is running
return 0
else if answerStudio contains "Adobe Illustrator 2019" then
tell application "/Applications/Adobe Illustrator CC 2019/Adobe Illustrator.app"
if it is not running then launch
end tell
it is running
return 0
else if answerStudio contains "Cancel" then
tell me to quit
end if
else if (Version2019 contains "true") then
--tell application "Finder"
set appVersion to "Adobe Illustrator 2019"
--end tell
else if (Version2020 contains "true") then
--tell application "Finder"
set appVersion to "Adobe Illustrator 2020"
--end tell
end if
end tell
Use the full path to the application, not just its name.
Also be aware that the application name displayed in Finder may not be its true file name.
Easiest way to get the app’s full path is just to drag-n-drop its icon into a Script Editor window.
Example:
tell application "/Applications/Adobe Illustrator 2020/Adobe Illustrator.app"
…
end tell
Related
I have albums and nested albums and folders in Photos application. I want my applescript to export images maintaining the Album or Folder structure that I have the in the application.
I tried scripts available online :
tell application "Finder"
set location_1 to (choose folder with prompt "Choose a folder to export into") as text
end tell
tell application "Photos"
set x to name of every folder
choose from list x with prompt "Choose a project to export"
set theP to item 1 of result
tell application "Finder" to make new folder at alias location_1 with properties {name:theP}
tell folder theP
set initflist to every folder
set initalist to every album
if initflist is equal to {} then
log "process albums"
processAlbums(initalist, location_1 & theP) of me
else
if initalist is not equal to {} then
log "process albums"
processAlbums(initalist, location_1 & theP) of me
end if
log "process sub folders "
processSfolders(initflist, (location_1 & theP)) of me
end if
end tell
end tell
on processAlbums(alist, apath)
tell application "Photos"
repeat with a in alist
tell a
set theimages to get media items of album a
set thename to name of a
tell application "Finder"
if not (exists folder thename in alias apath) then
make new folder at alias apath with properties {name:thename}
end if
set destination to apath & ":" & thename & ":"
end tell
with timeout of 6000 seconds
tell a
set settings to "JPEG - Original Size"
export theimages to alias destination
end tell
end timeout
end tell
end repeat
end tell
end processAlbums
on processSfolders(flist, fpath)
tell application "Photos"
repeat with a in flist
try
set thename to name of a
tell application "Finder"
if not (exists folder thename in alias fpath) then
make new folder at alias fpath with properties {name:thename}
end if
end tell
tell a
set sAlist to every album
set sflist to every folder
if sflist is equal to {} then
processAlbums(sAlist, fpath & ":" & thename) of me
else
if sAlist is not equal to {} then
processAlbums(sAlist, fpath & ":" & thename) of me
end if
processSfolders(sflist, fpath & ":" & thename) of me
end if
end tell
on error errMsg
log "error"
end try
end repeat
end tell
end processSfolders
The issue is that it gets names of only child albums and not top level albums. I have to maintain the entire structure of album or folder.
I do not know AppleScript and I tried tweaking this one but no luck so far. can I get a direction please?
You can get the name of the folders, and the albums contained in the folder, which will enable you to create the top level and child directories. Albums can only contain media items, not albums. Top level albums are classified as folders or containers. In the Applescript dictionary for Photos, it gives the definitions for these items.
tell application "Finder"
set location_1 to (choose folder with prompt "Choose a folder to export into") as text
end tell
tell application "Photos"
activate
set fds to folders
repeat with fd in fds
set fdName to name of fd
set abNames to every album of fd
if parent of fd is missing value then
my createFolders(fdName, abNames, location_1, fd)
end if
end repeat
end tell
on createFolders(fName, aAlbums, fPath, fd)
tell application "Finder"
if not (exists folder fName in alias fPath) then
make new folder with properties {name:fName} at fPath
end if
repeat with a in aAlbums
set aName to name of a
set aPath to ((fPath as alias) as text) & fName
if not (exists folder aName in alias aPath) then
make new folder with properties {name:aName} at aPath
end if
set exPath to ((aPath as alias) as text) & aName
my exportImages(a, exPath)
end repeat
end tell
tell application "Photos"
set rcFolders to every folder of fd
repeat with rcFd in rcFolders
set rcAlbums to every album of rcFd
set rcName to name of rcFd
set rcPath to ((fPath as alias) as text) & fName
my createFolders(rcName, rcAlbums, rcPath, rcFd)
end repeat
end tell
end createFolders
on exportImages(photoAlbum, destination)
tell application "Photos"
set theimages to get media items of photoAlbum
with timeout of 6000 seconds
tell photoAlbum
set settings to "JPEG - Original Size"
export theimages to alias destination
end tell
end timeout
end tell
end exportImages
EDIT - Error Handling
To handle errors, locate the command that is causing the error and wrap it in a try block. Solution could be to quit the application, so that the process will end, and maybe add a short delay and then continue with the script.
try
export theimages to alias destination
on error
-- statements to execute in case of error
error "The exporting of images failed to complete"
quit
end try
From the developer reference - When a command fails to complete in the allotted time (whether the default of two minutes, or a time set by a with timeout statement), AppleScript stops running the script and returns the error "event timed out". AppleScript does not cancel the operation—it merely stops execution of the script. If you want the script to continue, you can wrap the statements in a try statement. However, whether your script can send a command to cancel an offending lengthy operation after a timeout is dependent on the application that is performing the command. Further info regarding try statements.
Below is a simplfied version of a script I've been working (and had help with).
and is all working fine.
I'm wanting to develop this so when starting the script it shows dialog box with buttons with that do the below.
Button one Runs Both "Spec1" and "Spec2"
Button Two Runs Both "Spec2" and "Spec3"
Button Three shows a list dialog to select either "Spec1","Spec2","Spec3" (Like the script already does)
The final script will have a few more specs however this is enough to illustrate what I'm trying to achieve
Thanks
-- Spec realted file extensions
--Spec 1
set ListSpec1 to {"_0006", "_0007", "_0010", "_0011"}
--Spec 2
set ListSpec2 to {"_0000", "_0001", "_0002", "_0003", "_0004", "_0005"}
--Spec 3
set ListSpec3 to {"_0006"}
-- Obtain user choice of PS action
set PhotoshopActionList to {"Spec1", "Spec2", "Spec3"}
set ChosenSpec to choose from list PhotoshopActionList with title "Actions Picker" with prompt "Choose Action?"
-- If user cancels, then terminate the script
if ChosenSpec is false then
error number -128 (* user cancelled *)
else
set ChosenSpec to ChosenSpec's item 1 (* extract choice from list*)
end if
--Set image source folder
set SourceFolder to (choose folder with prompt "Choose Base Images:")
set FoldertoReplace to SourceFolder & ChosenSpec as text
--set image save folder
set DestinationFolder to (choose folder with prompt "Choose Save Location:")
set filelocation to DestinationFolder as text
--Setting Files list
tell application "Finder" to set filesList to files of entire contents of SourceFolder whose name ends with ".tif"
repeat with CurrentFile in filesList
tell application "Finder"
set NameF to name of CurrentFile
set currentFileAlias to (CurrentFile as alias) as text
end tell
-- Canadian Files Lists
if ChosenSpec is "Spec1" then
set theListSpecToUse to ListSpec1
else if ChosenSpec is "Spec2" then
set theListSpecToUse to ListSpec2
else
set theListSpecToUse to ListSpec3
end if
-- the file name contains a valid pattern, then process the file
if FNameOK(NameF, theListSpecToUse) then
--open photoshop
tell application "Adobe Photoshop CC 2017"
open alias currentFileAlias
--Canadain Actions
if ChosenSpec is "Spec1" then
do action "Spec1" as text from "Specs"
else if ChosenSpec is "Spec2" then
do action "Spec2" as text from "Specs"
else if ChosenSpec is "Spec3" then
do action "Spec3" as text from "Specs"
end if
--Saving to Format
-- Canadian Saves
if ChosenSpec is "Spec1" then
save current document in filelocation as TIFF with options {class:TIFF save options, image compression:LZW, transparency:true, embed color profile:true}
else if ChosenSpec is "Spec2" then
save current document in filelocation as TIFF with options {class:TIFF save options, image compression:LZW, transparency:true, embed color profile:true}
else
save current document in filelocation as PNG with options {class:PNG save options, compression:9, interlaced:false} appending no extension with copying
end if
--Close Photoshop Document
close current document without saving
end tell
end if
end repeat
on FNameOK(Local_Name, LocalList) -- check if the file name contains an element of the list
set LocalCheck to false
repeat with OneItem in LocalList
if Local_Name contains OneItem then
return true
end if
end repeat
return false
end FNameOK
I am using the below script for few months. It ask the user to select from the list and copy paste the text in MS Word and run some VB Macro and save the file as Text file.
tell application "Finder"
if not (exists folder "Test" of desktop) then make new folder at desktop with properties {name:"Test"}
end tell
set desktopTestFolder to (path to desktop folder as text) & "Test:"
set mychoice to (choose from list {"PS List", "AA Table", "PS Legend", "PO Chart", "MD"} with prompt "Please select which sound you like best" default items "None" OK button name {"Play"} cancel button name {"Cancel"})
if mychoice is false then error number -128 -- user canceled
tell application "Microsoft Word"
set theContent to content of text object of selection
copy object text object of selection
set newDoc to make new document
delay 2
tell application "System Events"
tell process "Microsoft Word"
keystroke "v" using command down
end tell
end tell
run VB macro macro name "Normal.NewMacros.Clean"
run VB macro macro name "Normal.Module9.bold"
save as newDoc file format format Unicode text file name (desktopTestFolder & mychoice & ".txt")
close document 1 saving no
end tell
But when I try it to put in an handler it not works. What I have tried is:
tell application "Finder"
if not (exists folder "Test" of desktop) then make new folder at desktop with properties {name:"Test"}
end tell
set desktopTestFolder to (path to desktop folder as text) & "Test:"
set mychoice to (choose from list {"PS List", "AA Table", "PS Legend", "PO Chart", "MD"} with prompt "Please select which sound you like best" default items "None" OK button name {"Play"} cancel button name {"Cancel"})
if mychoice is false then error number -128 -- user canceled
set mychoice to mychoice as text
if mychoice is equal to "PS List" then
handler1()
else
handler2()
end if
on handler1()
tell application "Microsoft Word"
set theContent to content of text object of selection
copy object text object of selection
set newDoc to make new document
delay 2
tell application "System Events"
tell process "Microsoft Word"
keystroke "v" using command down
end tell
end tell
run VB macro macro name "Normal.NewMacros.EDCleanup1"
run VB macro macro name "Normal.Module9.bold"
save as newDoc file format format Unicode text file name (desktopTestFolder & mychoice & ".txt")
close document 1 saving no
end tell
end handler1
on handler2()
tell application "Microsoft Word"
run VB macro macro name "Normal.NewMacros.EDCleanup1"
run VB macro macro name "Normal.Module9.bold"
save as newDoc file format format Unicode text file name (desktopTestFolder & mychoice & ".txt")
close document 1 saving no
end tell
end handler2
Please let me know, Where I am wrong?
Thanks
Josh
You didn't say what result you get when you say "it not works". Do you get an error? Do you get nothing? Do you get the same result when you select "PS List" versus the others?
The error I see is that you never bring Microsoft Word to the front. This is necessary for when you're using UI scripting and the keystroke command. Add 'activate' to your Word tell blocks.
tell application "Microsoft Word"
activate
set theContent to content of text object of selection
…
Also, yes, your variable desktopTestFolder loses scope. You can make the variable a global property by placing this at the front of your script:
property desktopTestFolder: ""
I am at my wit's end. I have tried all variations to get this script to work. The error I get is Adobe Photoshop CS6 got an error: Can’t get current document. and the highlighted script error is my "export in file newFileName.." block. I've tried putting alias in different positions, using file, not using file. Also I get this error message, but the actual script seems to stop working right after "set docName to name of docRef"
And basically I just copied this code from another script that was working fine and just changed a save this file... to a export this file...
-- set the folders that you want to use
set inputFolder to choose folder with prompt "Choose the folder of images to downsize."
set pathToDesktop to (path to desktop folder as string)
set outputFolder to pathToDesktop & "PhotoshopRetina:"
tell application "Finder"
set filesList to files in folder inputFolder
if not (exists folder outputFolder) then
make new folder at desktop with properties {name:"PhotoshopRetina"}
end if
end tell
with timeout of 86400 seconds
tell application "Adobe Photoshop CS6"
set display dialogs to never
close every document saving no
end tell
repeat with aFile in filesList
tell application "Finder"
-- The step below is important because the 'aFile' reference as returned by
-- Finder associates the file with Finder and not Photoshop. By converting
-- the reference below 'as alias', the reference used by 'open' will be
-- correctly handled by Photoshop rather than Finder.
set theFile to aFile as string
set theFileName to name of aFile
set theFileInfo to info for alias theFile
if kind of theFileInfo is "Adobe Photoshop JPEG file" then
my retinaDisplay(theFile)
end if
end tell
end repeat
end timeout
end
on retinaDisplay(theFile)
tell application "Adobe Photoshop CS6"
open alias theFile
set docRef to the current document
-- Convert the document to a document mode that supports saving as jpeg
if (mode of docRef is not RGB) then
change mode docRef to RGB
end if
tell docRef
set color profile kind to none
end tell
set infoRef to get info of docRef
set docName to name of docRef
set docBaseName to getBaseName(docName) of me
set newFileName to (my outputFolder as string) & docBaseName & ".jpg"
tell current document
export in file newFileName as save for web with options {class:save for web export options, web format:JPEG, embed color profile:false, quality:45} with copying
end tell
close current document without saving
end tell
end retinaDisplay
-- Returns the document name without extension (if present)
on getBaseName(fName)
set baseName to fName
repeat with idx from 1 to (length of fName)
if (item idx of fName = ".") then
set baseName to (items 1 thru (idx - 1) of fName) as string
exit repeat
end if
end repeat
return baseName
end getBaseName
end
If I open an image in photoshop I can run this code with no errors.
set f to (path to desktop as text) & "test.jpg"
tell application "Adobe Photoshop CS6"
tell current document
export in file f as save for web
end tell
end tell
However, if I additionally add your "with options" code then I get your error. I don't even know what the "with copying" part is. I don't think that means anything to photoshop. So the problem is not with the "current document". The problem is with your options. You must be doing that part wrong.
Good luck.
I'm trying to make an applescript that let's me change the desktop picture to a random picture in a folder on my hard drive
tell application "Finder"
set desktopPictures to folder "Path:To:Desktop:Pictures:"
set fileList to name of every file of desktopPictures
set theNum to random number from 1 to (count fileList) with seed ((time of (current date)) * 4)
set fileName to item theNum of fileList
set desktop picture to file fileName in desktopPictures
end tell
So far it works perfectly, the only issue I have is when I connect another monitor, his desktop picture won't change.
I tried solving this problem with the following code I found making a web search
tell application "Finder"
set desktopPictures to folder "Path:To:Desktop:Pictures:"
set fileList to name of every file of desktopPictures
set theDesktops to a reference to every desktop
repeat with aDesktop in theDesktops
set theNum to random number from 1 to (count fileList) with seed ((time of (current date)) * 4)
set fileName to item theNum of fileList
set picture of aDesktop to file fileName in desktopPictures
end repeat
end tell
But this code won't compile as I get a syntax error saying:
Expected class name but found property.
With desktop highlighted on row 4
You have omitted the tell application "System Events" block from the code you found.
In Applescript some commands exist in the dictionary of specific applications and must be referenced with a 'tell application' block. In this case the 'every desktop' call is in the "System Events" app.
Try this.
tell application "Finder"
set desktopPictures to folder "Path:To:Desktop:Pictures:"
set fileList to name of every file of desktopPictures
tell application "System Events"
set theDesktops to a reference to every desktop
end tell
repeat with aDesktop in theDesktops
set theNum to random number from 1 to (count fileList) with seed ((time of (current date)) * 4)
set fileName to item theNum of fileList
set picture of aDesktop to file fileName in desktopPictures
end repeat
end tell