Since I updated my illustrator to CC 2020 (24.0) when I execute this command in apple script
set placedRef to make new placed item in layer "Layer1" of current document with properties {file path:pfilepath} without dialogs
Illustrator is displaying a popup : "Select a File Format to open file:" with 3 choices : Pixar, PNG or Targa.
Whatever I choose, nothing is inserted.
This exact same command works on illustrator CC 2019 and not popup is displayed.
Here is the full code to reproduce :
on run argv
tell application "Adobe Illustrator"
activate
set user interaction level to never interact
set placedRef to make new placed item in layer "ignore" of current document with properties {file path:item 1 of argv} without dialogs
end tell
end run
Command example to run the script :
osascript test.scpt :Users:myusername:Download:test.pdf
AI 2020 has changed the type of the file path property from a ‘file’ value to a POSIX path string, breaking compatibility with existing scripts (more info). Change your shell script to pass a POSIX path instead.
Related
There are many posts that explain how to drag-and-drop things into an open Terminal window. But what I would like to do is to tell Terminal to drag-and-drop a previously selected directory onto another application like VSCode or Renamer. I have not found any documentation for that. Is it at all possible? And if so, would somebody please point me to a documentation?
UPDATE:
I'd like to clarify my question with what I intend to do:
Pre requisites:
a "work folder" contains folders and files that shall be renamed
the renaming is done by an application called "A better finder renamer" (which allows presets)
An "Automator" (MacOS app) action shall imitate these steps:
the "work folder" is right clicked
the folder is drag-and-dropped onto the ABFR, which initiates the currently active preset
other actions via bash (like 'mv .//.* ./') ...
It is the "drag-and-drop" part of the Automator action that presents a riddle for me.
The "drag-and-drop" operation is manual operation. In AppleScript, instead the command to open the file or folder is given to the destination application itself.
Second thing to keep in mind. Getting Terminal's current working directory is easy with its do script "pwd" command. But the result of the do script Terminal command returned to the script is always the window tab, not the result of the pwd shell command. One solution is to redirect (remember) the result of pwd in a temporary text file.
set tempFolder to (path to temporary items folder from user domain)
set temp to POSIX path of tempFolder & "workingDirectory.txt"
tell application "Terminal" to do script ("pwd > " & temp) in selected tab of window 1
set curDirPosixPath to paragraph 1 of (read file ((tempFolder as text) & "workingDirectory.txt"))
set curDirHFSPath to curDirPosixPath as POSIX file as Unicode text
tell application "Visual Studio Code" to open curDirHFSPath
.
NOTE: other possible solution (I don't like) is parsing the text contents of Terminal window after pwd command execution. You can get contents using property contents (of selected tab of front window).
Open Automator, choose create New Document.
Choose create new Quick Action (service).
Set workflow receives current folders in any application.
From library Add Run AppleScript action. Edit it contents:
on run {input, parameters}
set curDirHFSPath to (item 1 of input) as text
tell application "Visual Studio Code" to open curDirHFSPath
end run
Save this Quick Action as service. Now when right-clicking the folder, opens the context menu, where you can choose and run this service.
I've been breaking my head for the past few hours trying to solve this.
I've done a lot of research trying to find a clear answer, but no luck so far.
I'm doing some automation tests for an Adobe Suite automated workflow.
I'll be automating Photoshop, InDesign and After Effects files using AppleScript and ExtendScript.
I wrote this test code for InDesign 2021 and it works just fine:
set TheTitle to "Test Title"
tell application "Adobe InDesign 2021"
activate
open file "path:to:folder:test.indd"
set jsx_script to "/path/to/folder/test.jsx"
do script jsx_script language javascript with arguments {TheTitle}
close every document saving no
quit
end tell
I use the same principle to work with After Effects 2022 and the do script portion keeps throwing the Expected end of line, etc. but found “script”. (-2741) error.
This is the working version of the script for AE:
set jsx_file to "/path/to/folder/test_ae.jsx"
tell application "Adobe After Effects 2022"
activate
DoScriptFile jsx_file
end tell
If I only type do the Script Editor colors it green (as a variable instead of a command). So, neither do script nor do JavaScript are working.
DoScriptFile does run the JSX within AE, but the problem is that I need to pass the variables into the JSX file and DoScriptFile won't allow it.
So, I'm looking for either a way to pass arguments/variables to the JSX via DoScriptFile or a solution for do script not working with AE.
You can set variables before doing the script file:
set TheTitle to "Test Title"
tell application "Adobe After Effects 2022"
activate
DoScript "var TheTitle = \"" & TheTitle & "\";"
DoScriptFile "/path/to/folder/test_ae.jsx"
end tell
I used to use two AppleScript scripts to find out the file name of the actual wallpaper image from desktop 1 and desktop 2 (dual monitor mode) under macOS Mojave. One script for the main monitor and another one for the second monitor. Under macOS Catalina the scripts are not working anymore.
Here is the script:
tell application "System Events"
set posix_path to (pictures folder of desktop 2)
set picPath to (POSIX file posix_path) as string
end tell
set thePictures to (do shell script "sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.picture_id=7 and preferences.data_id=data.ROWID\"")
set fullPath to picPath as string
set rotationImage to fullPath & thePictures
tell application "Finder"
try
set aliasItem to item rotationImage
if class of aliasItem is alias file then
reveal original item of aliasItem
end if
end try
end tell
Here is the error message:
tell application "System Events"
get pictures folder of desktop 1
--> "/Users/peter/Library/Caches/com.apple.preference.desktopscreeneffect.desktop/69948584/DSKPhotosRootSource"
get POSIX file "/Users/peter/Library/Caches/com.apple.preference.desktopscreeneffect.desktop/69948584/DSKPhotosRootSource"
--> error number -1728 from POSIX file "/Users/peter/Library/Caches/com.apple.preference.desktopscreeneffect.desktop/69948584/DSKPhotosRootSource"
end tell
tell current application
do shell script "sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.picture_id=1 and preferences.data_id=data.ROWID\""
--> "13725B"
end tell
tell application "Finder"
get item "Macintosh HD:Users:peter:Library:Caches:com.apple.preference.desktopscreeneffect.desktop:69948584:DSKPhotosRootSource13725B"
--> error number -1728 from item "Macintosh HD:Users:peter:Library:Caches:com.apple.preference.desktopscreeneffect.desktop:69948584:DSKPhotosRootSource13725B"
end tell
Tried to find the problem but couldn't find a solution. I am not an experienced AppleScript writer. Hope somebody can help.
On Catalina and Mojave, I'm able to get the current wallpaper by using a sqlite command similar to yours:
sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db "select * from data" | tail -2
Or in Applescript:
do shell script "sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db 'select * from data' | tail -2"
On my Mac, the last 2 items in the data table appear to be some combination of the most recently set wallpaper and last 2 displays that were most recently set, so I tail the list. Like you, I'm also using a large folder of wallpapers and I have it set to change every 30 minutes. As long as I don't manually change a wallpaper, the last 2 items are consistently the names of the 2 active wallpapers because both monitors change at the same time every 30 minutes.
Something to note: When you are using a Folder with the "Change picture:" checkbox checked, the items returned from select * data is just the file name (i.e., wallpaper.jpg). If you've set the wallpaper to a single image, the item returned from the select command is the full path of the image (i.e., /path/to/folder/wallpaper.jpg). Since I'm using a folder, so I get just the image names in my select results. Then I can split the 2 names by newline to get each wallpaper name in an array and then open them. Here's my whole script:
#!/bin/bash
#reads and opens the last 2 items from the 'data' table in the desktoppicture.db sqlite db
last_two=`sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db "select * from data" | tail -2`
IFS=$'\n' read -rd '' -a y <<<"$last_two"
#echo "first is ${y[0]}"
#echo "second is ${y[1]}"
open /Users/myusername/Pictures/Desktop\ Pictures/${y[0]}
open /Users/myusername/Pictures/Desktop\ Pictures/${y[1]}
I realize you asked an AppleScript question and this is largely a bash script answer, but the do shell script item at the top of my answer should get you going enough to be able to capture and manipulate the image names inside of AppleScript.
Just to close this out, I use this bash script in Alfred using a keyword "retire" to retire a wallpaper I'm tired of. I type the keyword, this script runs to open the images in Preview, another script runs to open my Desktop Pictures folder and a Desktop Pictures Retired folder and then I manually move the photo into the Retired folder.
If you currently have two monitors connected and you're simply looking to retrieve the names of the Desktop Wall Papers for each, this following Apple script code should be what you're looking for.
tell application "System Events"
set everyDesktop to desktops
set desktopOnePicture to picture of item 1 of everyDesktop
set desktopTwoPicture to picture of item 2 of everyDesktop
end tell
I can't guarantee the code below will fair any better than the solution already posted, but it should, in theory, target desktop images per screen (monitor) rather than by desktop (space). However, I don't have Mojave or Catalina, or a computer to test this out:
use framework "AppKit"
property NSScreen : a reference to NSScreen in the current application
property NSWorkspace : a reference to NSWorkspace in the current application
property currentScreen : a reference to the mainScreen of NSScreen
on screen(i as integer)
local i
if i = 0 then return the currentScreen()
return NSScreen's screens()'s item i
end screen
on desktopImageURLForScreen:(i as integer)
local i
set S to screen(i)
tell NSWorkspace's sharedWorkspace() to return the ¬
desktopImageURLForScreen_(S) as «class furl»
end desktopImageURLForScreen:
return the POSIX path of my desktopImageURLForScreen:0
The bottom line is the one you will most likely want to experiment with, by changing the index number passed to the handler. If you have three monitors, then they would each be identified by one of the indices 1, 2, or 3 (I can't predict how index corresponds to arrangement of monitors). Index 0 will always refer to the screen that currently has keyboard focus.
Trying to make Automator workflow that uses "Convert to TXT Document" for pdf to txt convertion. But while running, Abbyy FineReader window becomes active. Is it possible to run in in silent mode or with minimized window?
This AppleScript works for me using the latest version of Sierra. Tested on my system, it did not bring Abbyy FineReader to the foreground.
set thePDF to (choose file)
tell application "FineReader"
set resultFile to export to txt thePDF ¬
from file thePDF
end tell
Your new text file should appear in the same directory as your original PDF
I'm not using Automator so I do not know which method you are going to use to pass the PDF file to this AppleScript. For testing purposes, I used to the “choose file” command. If you are using Automator to pass the PDF file that you specified in a previous Automator action, you can just remove the “choose file” command from the code. Anyway, all you need to do is add a “run AppleScript” command in your Automator workflow.
If you are going to remove the “choose file” command, you'll need to re-define the value for the variable thePDF
NOTE FineReader actually has an extensive AppleScript dictionary. My answer included a minimal version of many other options for the exporting as text. Here is a full version example of options
tell application "FineReader"
set resultFile to export to txt directParamFile ¬
from file fromFileFile ¬
ocr languages enum ocrLanguagesEnumLanguageListType ¬
saving type savingTypeSaveSettingsEnum ¬
retain layout retainLayoutTxtLayout ¬
keep page numbers headers and footers keepPageNumbersHeadersAndFootersBoolean ¬
keep line breaks and hyphenation keepLineBreaksAndHyphenationBoolean ¬
insert page break character as page separator insertPageBreakCharacterAsPageSeparatorBoolean ¬
use blank lines useBlankLinesBoolean ¬
encoding encodingEncodingEnum
end tell
I decided not to use FineReader applet. Instead I migrate to stack: tesseract + ImageMagick + gs.
If anybody is interested, I attach my sollution below.
Automator shell script
export PATH=/usr/local/bin:$PATH
/usr/local/bin/convert -density 300 "$#" -depth 8 -strip -background white -alpha off image.tiff
/usr/local/bin/tesseract -l rus image.tiff ~/Desktop/OCR
rm image.tiff
And the
Automator workflow
You could try this applescript in the script editor, replacing the file paths to your files. I don't have the program installed, so I haven't tested it. If it doesn't work, maybe it's something you can build on to get the result you're after.
tell application "FineReader" activate
tell application "System Events" set visible of process "FineReader" to false
tell application "FineReader"
export to txt "/Path/to/filename/File_to_OCR.pdf" from file "/Path/to/filename/File_to_OCR.pdf"
end tell
I am trying to automatically delete the preview icon of a PNG file (or many files) that I have generated with Photoshop.
I know how to manually do this: I can select the files, hit command+shift+i, select the icon on that window and hit the delete key to delete the files; but I would prefer to do this automatically with an AppleScript (or a Terminal command that I will then embed in my AppleScript with a do shell command)... I have searched the web for days but I have found nothing that helps me.
So, does anyone know of an AppleScript or Terminal command that could be used to delete the preview icon of a PNG (or JPEG) file?
You can use the setIcon method from the NSWorkspace class to delete icon of the file. https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/
A Cocoa-AppleScript Applet
use framework "AppKit"
use scripting additions
set myFiles to choose file with prompt "Select PNG files" with multiple selections allowed
set sharedWk to current application's NSWorkspace's sharedWorkspace()
repeat with tFile in myFiles
(sharedWk's setIcon:(missing value) forFile:(POSIX path of tFile) options:0)
end repeat
Or an AppleScript using a do shell script
set pyScript to quoted form of "from AppKit import NSWorkspace; import sys; NSWorkspace.sharedWorkspace().setIcon_forFile_options_(None, sys.argv[1].decode('utf-8'), 0)"
set myFiles to choose file with prompt "Select PNG files" with multiple selections allowed
repeat with tFile in myFiles
do shell script "/usr/bin/python -c " & pyScript & " " & (quoted form of POSIX path of tFile)
end repeat
Here's some links:
https://en.wikipedia.org/wiki/Cocoa_(API)
https://developer.apple.com/library/mac/releasenotes/ScriptingAutomation/RN-AppleScriptObjC/
https://en.wikipedia.org/wiki/PyObjC
JavaScript with Objective-C Bridge --> https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html