What's the REAL problem, please?


Brian Christmas
 

G’day

I’m trying altering code in my printing App to be able to use almost ANY recent version of different printing Apps.

So, I've resorted to trying to open each app with its bundle identifier.

Compiled OK (Acrobat, Illustrator, InDesign), until I got to GraphicConverter (using Script Debugger), where I found the bundle id has a number, the same as the App version number (10)

So, I wrote code to overcome this, then found certain aspects of my GraphicConverter handler will no longer compile.

Trouble is, is it the Compiler, or GraphicConverter???

I’ve whipped of a request to Thorsten Lemke, but also thought I’d bounce the question of these two groups.

Below is a snippet I wrote to test the problem.

Any thoughts, particularly from the Authors of Script Debugger?

Any alternative methods? This is REALLY important, please!

Regards

Santa

property theItem : ((path to desktop as text) & "Numbers_Chart.jpg")

tell application "Finder" to set theApps to (name of (every item of folder (path to applications folder))) as list

repeat with theApp2 in theApps
if theApp2 contains "GraphicConverter" then
set theUserApp to application theApp2
exit repeat
end if
end repeat

tell application "System Events"
set theApp to bundle identifier of (info for (path to theUserApp)) — Returns "com.lemkesoft.graphicconverter10"
end tell

tell application id theApp to activate

tell application "Finder" to set theProcesses to (name of processes) as list
repeat with theApp2 in theProcesses
if theApp2 contains "GraphicConverter" then
set theUserProcess to theApp2 as text
exit repeat
end if
end repeat

tell (application id theApp)
activate
# silentopen file (my theItem) — Won’t compile
open file (my theItem)
tell window 1
try
set TheRes to resolution
set resolutionChangeFlag to false
if item 1 of TheRes < 600 then
set item 1 of TheRes to 600
set resolutionChangeFlag to true
end if
if item 2 of TheRes < 600 then
set item 2 of TheRes to 600
set resolutionChangeFlag to true
end if
#if resolutionChangeFlag then change resolution to TheRes with resample — Won’t compile
end try
end tell
end tell


Shane Stanley
 

On 2 Sep 2017, at 11:46 am, Brian Christmas <ozsanta@...> wrote:

Any thoughts, particularly from the Authors of Script Debugger?
Yes: read the AppleScript Language Guide, or buy one of the beginner AppleScript books. This has nothing to do with Script Debugger or GraphicConverter -- it's AppleScript 101: if you use a variable for the target, either name or id, there's no way AppleScript can know at compile time which application's terminology to use.

This is REALLY important
This is REALLY basic.

--
Shane Stanley <sstanley@...>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


Shane Stanley
 

On 2 Sep 2017, at 12:16 pm, Shane Stanley <sstanley@...> wrote:

read the AppleScript Language Guide
Hint: look up "using terms from".

--
Shane Stanley <sstanley@...>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


Brian Christmas
 

Shane, look, I really, really appreciate your advice, but I cannot for the life of me see how it changes my situation.

In order to get ‘using terms from’ to work, I have to enter a non-variable item, such as in my example below. The commented line #using terms from   (application id theApp) shows what I WANT to use, but still doesn’t work.

To get using terms from to work, I’m still restricted to knowing the exact name of the bundle identifier, which I REALLY absolutely need as a variable.

The possible name are …

GraphicConverter

GraphicConverter 10

GraphicConverter 11     (the next release)

Even other App works with a defined bundle identifier that does not alter between releases, but Thorsten in his infinite wisdom, has decided to link bundle indentifiers to version releases from now on. Version releases have numbers because of App Store release. Why he decided to add the same number to his bundle identifiers only he knows, but I’ve sent a grumbling email to him pointing out the problem it causes.

Is there any way around this situation? OR, am I up the proverbial creek without a paddle?

Regards

Santa

property theItem : ((path to desktop as text) & "Numbers_Chart.jpg")

tell application "Finder" to set theApps to (name of (every item of folder (path to applications folder))) as list

repeat with theApp2 in theApps
if theApp2 contains "GraphicConverter" then
set theUserApp to application theApp2
exit repeat
end if
end repeat

tell application "System Events"
set theApp to bundle identifier of (info for (path to theUserApp)) as text
end tell

tell application id theApp to activate

tell application "Finder" to set theProcesses to (name of processes) as list
repeat with theApp2 in theProcesses
if theApp2 contains "GraphicConverter" then
set theUserProcess to theApp2 as text
exit repeat
end if
end repeat

using terms from application "GraphicConverter 10"


# if I use the line below instead, Script Editor alters it to the same as the line above
# using terms from   (application id "com.lemkesoft.graphicconverter10”) — SEE, he damnwell alters the bundle identifier between releases!!!


#using terms from   (application id theApp) -- Fails
tell (application id theApp)
activate
silentopen file (my theItem) — NOW WORKS!!
#open file (my theItem)
tell window 1
try
set TheRes to resolution
set resolutionChangeFlag to false
if item 1 of TheRes < 600 then
set item 1 of TheRes to 600
set resolutionChangeFlag to true
end if
if item 2 of TheRes < 600 then
set item 2 of TheRes to 600
set resolutionChangeFlag to true
end if
if resolutionChangeFlag then change resolution to TheRes with resample — NOW WORKS!!
end try
end tell
end tell
end using terms from


Brian Christmas
 

Thank you Andrew

However, as  cannot test your suggestion, I want to make myself absolutely clear on my understanding of what you’re saying.

Thorsten has changed his App name from just ‘GraphicConverter’, to now  ‘GraphicConverter 10’, and presumably in the future to  ‘GraphicConverter 11’,  ‘GraphicConverter 12', etc.. He rarely changes his dictionary options.

If (because I’m always recompiling), I use  ‘GraphicConverter 10’ now, and the present bundle identifier  is “com.lemkesoft.graphicconverter10”, will future bundle identifiers “com.lemkesoft.graphicconverter11”, “com.lemkesoft.graphicconverter12” work with my code?


Thank you for offering a ray of hope!!

Regards

Santa


On 2 Sep 2017, at 3:59 pm, Andrew Oliver <camelot@...> wrote:



Sent from my iPhone

On Sep 1, 2017, at 10:05 PM, Brian Christmas <ozsanta@...> wrote:

To get using terms from to work, I’m still restricted to knowing the exact name of the bundle identifier, which I REALLY absolutely need as a variable.

At compile time, yes but that is _largely_ irrelevant at rub time

You can put anything in your 'using terms from' statement - I'd go with 'Graphic Converter' - and when you hit compile the Script Editor will look for a matching application. If it can't find one it will prompt you for which application you're referring to, then it will load the appropriate dictionary, compile the app, and you're good to go. This app is *never* referenced again - at least until you recompile. 

The only time this could become an issue is if the dictionary varies between application versions and there is no backwards compatibility (which is the responsibility of the application developer, not you), such as if the commands in older versions are not supported in the newer version. 

Andrew
:)


Shane Stanley
 

On 2 Sep 2017, at 3:05 pm, Brian Christmas <ozsanta@...> wrote:

Even other App works with a defined bundle identifier that does not alter between releases, but Thorsten in his infinite wisdom, has decided to link bundle indentifiers to version releases from now on. Why he decided to add the same number to his bundle identifiers only he knows, but I’ve sent a grumbling email to him pointing out the problem it causes.
Blaming someone else every time you fail to understand something gets very tiresome after a while. It's not something peculiar to GraphicConverter -- you may have seen com.apple.ScriptEditor2, for example -- and if more developers did it, it would make writing scripts where people use multiple versions a damn sight easier. Thorsten deserves a thankyou note, not blame-shifting.

If the command is going to work with every version of GraphicConverter, then it doesn't matter which version's name you use terms from. And if it isn't going to work with every version of GraphicConverter, you can't use it anyway.

Here's the first link that comes up on a Google search on "using terms from":

A terms block dictates which application's dictionary AppleScript should get the enclosed terminology from, without actually targeting that application. Terminology is resolved at compile time; therefore the application must be a literal application specifier (otherwise there's a compile-time error, "Can't make some data into the expected type"). A terms block is important only at compile time (and decompile time); it is effectively ignored at runtime.
It's from 'AppleScript: The Definitive Guide', 2nd Edition by Matt Neuburg. You should read it some time.

--
Shane Stanley <sstanley@...>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>