Re: [Bibdesk-users] JXA ScriptHook

2019-05-04 Thread Christiaan Hofman
Thanks, I fixed them. Missing parens and the “in” should be “of” in the 
for-loop.

Christiaan

> On 4 May 2019, at 03:11, Mahmood Shafeie Zargar  wrote:
> 
> That sample script has a problem in the for loop, as well as in fetching the 
> property value. That still doesn't work for me.
> 
> But this one works:
> 
> function performBibDeskActionWithPublications(thePubs, {forScriptHook : 
> theScriptHook }) {
> var theName = theScriptHook.name();
> var theID = theScriptHook.id <http://thescripthook.id/>();
> var theField = theScriptHook.fieldName();
> var oldValues = theScriptHook.oldValues();
> var newValues = theScriptHook.newValues();
> var theKeys = [];
> var theTitles = [];
> 
> for (var i=0, aPub; aPub=thePubs[i]; i++) {
> theKeys.push(aPub.citeKey());
> theTitles.push(aPub.fields.byName("Author").value());
> }
> 
> var app = Application.currentApplication();
> app.includeStandardAdditions = true;
> 
> app.displayDialog("Name: " + theName + "\n" + "ID: " + theID + "\n" + "Cite 
> Keys: " + theKeys + "\n" + "Titles: " + theTitles + "\n" + "Field name: " + 
> theField + "\n" + "Old values: " + oldValues + "\n" + "New values: " + 
> newValues, { buttons :["OK"], defaultButton : 1 });
> }
> 
> 
> Best,
> Mah
> 
> From: Christiaan Hofman 
> Sent: May 2, 2019 7:22 PM
> To: For general discussion about using BibDesk
> Subject: Re: [Bibdesk-users] JXA ScriptHook
>  
> 
> 
>> On 2 May 2019, at 18:55, Christiaan Hofman > <mailto:cmhof...@gmail.com>> wrote:
>> 
>> 
>> 
>>> On 2 May 2019, at 18:12, Christiaan Hofman >> <mailto:cmhof...@gmail.com>> wrote:
>>> 
>>> 
>>> 
>>>> On 2 May 2019, at 17:22, Mahmood Shafeie Zargar >>> <mailto:m...@msn.com>> wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> I would like to know where I can find an example of a script hook written 
>>>> in JavaScript. 
>>>> 
>>>> I have tried things like this to no avail:
>>>> 
>>>> functionperformBibDeskActionWithPublications(pubs, scriptHook) {
>>>> 
>>>> }
>>>> 
>>>> The function code runs, but no value is loaded in the parameters.
>>>> 
>>>> Thanks,
>>>> Mah
>>> 
>>> 
>>> I haven’t tried using JXA script hooks, but I think they should work. 
>>> Though it could be JXA hangs BibDesk, because of bugs with JXA (that Apple 
>>> says aren’t bugs but just how it works), that will be fixed in the next 
>>> release.
>>> 
>>> I am not an expert on JS, but shouldn’t it be:
>>> 
>>> function performBibDeskActionWithPublications(pubs, 
>>> {forScriptHook:scriptHook}) {
>>> }
>>> 
>>> Christiaan
>> 
>> 
>> Here is the JXA version for the sample script hook:
>> 
>> function performBibDeskActionWithPublications(thePubs, { forScriptHook : 
>> theScriptHook }) {
>> var theName = theScriptHook.name();
>> var theID = theScriptHook.id <http://thescripthook.id/>();
>> var theField = theScriptHook.fieldName();
>> var oldValues = theScriptHook.oldValues();
>> var newValues = theScriptHook.newValues();
>> var theKeys = [];
>> for (var aPub in thePubs) {
>> theKeys.push(aPub.citeKey);
>> }
>> var app = Application.currentApplication();
>> app.includeStandardAdditions = true;
>> app.displayDialog("Name: " + theName + "\n" + "ID: " + theID + "\n" + "Cite 
>> Keys: " + theKeys + "\n" + "Field name: " + theField + "\n" + "Old values: " 
>> + oldValues + "\n" + "New values: " + newValues, { buttons : ["OK"], 
>> defaultButton : 1 });
>> }
>> 
>> It works for me, at least with the current nightly.
>> 
>> Christiaan
>> 
> 
> 
> I’ve added some sample JXA script hooks on the Wiki.
> 
> Christiaan

___
Bibdesk-users mailing list
Bibdesk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-users


Re: [Bibdesk-users] JXA ScriptHook

2019-05-03 Thread Mahmood Shafeie Zargar
That sample script has a problem in the for loop, as well as in fetching the 
property value. That still doesn't work for me.

But this one works:


function performBibDeskActionWithPublications(thePubs, {forScriptHook : 
theScriptHook }) {

var theName = theScriptHook.name();

var theID = theScriptHook.id();

var theField = theScriptHook.fieldName();

var oldValues = theScriptHook.oldValues();

var newValues = theScriptHook.newValues();

var theKeys = [];

var theTitles = [];


for (var i=0, aPub; aPub=thePubs[i]; i++) {

theKeys.push(aPub.citeKey());

theTitles.push(aPub.fields.byName("Author").value());

}


var app = Application.currentApplication();

app.includeStandardAdditions = true;


app.displayDialog("Name: " + theName + "\n" + "ID: " + theID + "\n" + "Cite 
Keys: " + theKeys + "\n"  + "Titles: " + theTitles + "\n" + "Field name: " + 
theField + "\n" + "Old values: " + oldValues + "\n" + "New values: " + 
newValues, { buttons :["OK"], defaultButton : 1 });

}


Best,
Mah

____________
From: Christiaan Hofman 
Sent: May 2, 2019 7:22 PM
To: For general discussion about using BibDesk
Subject: Re: [Bibdesk-users] JXA ScriptHook



On 2 May 2019, at 18:55, Christiaan Hofman 
mailto:cmhof...@gmail.com>> wrote:



On 2 May 2019, at 18:12, Christiaan Hofman 
mailto:cmhof...@gmail.com>> wrote:



On 2 May 2019, at 17:22, Mahmood Shafeie Zargar 
mailto:m...@msn.com>> wrote:

Hi,

I would like to know where I can find an example of a script hook written in 
JavaScript.

I have tried things like this to no avail:

functionperformBibDeskActionWithPublications(pubs, scriptHook) {

}

The function code runs, but no value is loaded in the parameters.

Thanks,
Mah

I haven’t tried using JXA script hooks, but I think they should work. Though it 
could be JXA hangs BibDesk, because of bugs with JXA (that Apple says aren’t 
bugs but just how it works), that will be fixed in the next release.

I am not an expert on JS, but shouldn’t it be:

function performBibDeskActionWithPublications(pubs, {forScriptHook:scriptHook}) 
{
}

Christiaan

Here is the JXA version for the sample script hook:

function performBibDeskActionWithPublications(thePubs, { forScriptHook : 
theScriptHook }) {
var theName = theScriptHook.name();
var theID = theScriptHook.id<http://thescripthook.id/>();
var theField = theScriptHook.fieldName();
var oldValues = theScriptHook.oldValues();
var newValues = theScriptHook.newValues();
var theKeys = [];
for (var aPub in thePubs) {
theKeys.push(aPub.citeKey);
}
var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.displayDialog("Name: " + theName + "\n" + "ID: " + theID + "\n" + "Cite 
Keys: " + theKeys + "\n" + "Field name: " + theField + "\n" + "Old values: " + 
oldValues + "\n" + "New values: " + newValues, { buttons : ["OK"], 
defaultButton : 1 });
}

It works for me, at least with the current nightly.

Christiaan


I’ve added some sample JXA script hooks on the Wiki.

Christiaan

___
Bibdesk-users mailing list
Bibdesk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-users


Re: [Bibdesk-users] JXA ScriptHook

2019-05-03 Thread Mahmood Shafeie Zargar
Sorry for spamming. No worries, I found them. The link is on the top of the 
front page!

From: Mahmood Shafeie Zargar 
Sent: May 3, 2019 12:20 AM
To: For general discussion about using BibDesk
Subject: Re: [Bibdesk-users] JXA ScriptHook

Thanks! Very useful.

It definitely doesn't work here (1.6.22 (4794)).

Where can I get the nightly?

Best wishes,
Mah

From: Christiaan Hofman 
Sent: May 2, 2019 7:22 PM
To: For general discussion about using BibDesk
Subject: Re: [Bibdesk-users] JXA ScriptHook



On 2 May 2019, at 18:55, Christiaan Hofman 
mailto:cmhof...@gmail.com>> wrote:



On 2 May 2019, at 18:12, Christiaan Hofman 
mailto:cmhof...@gmail.com>> wrote:



On 2 May 2019, at 17:22, Mahmood Shafeie Zargar 
mailto:m...@msn.com>> wrote:

Hi,

I would like to know where I can find an example of a script hook written in 
JavaScript.

I have tried things like this to no avail:

functionperformBibDeskActionWithPublications(pubs, scriptHook) {

}

The function code runs, but no value is loaded in the parameters.

Thanks,
Mah

I haven’t tried using JXA script hooks, but I think they should work. Though it 
could be JXA hangs BibDesk, because of bugs with JXA (that Apple says aren’t 
bugs but just how it works), that will be fixed in the next release.

I am not an expert on JS, but shouldn’t it be:

function performBibDeskActionWithPublications(pubs, {forScriptHook:scriptHook}) 
{
}

Christiaan

Here is the JXA version for the sample script hook:

function performBibDeskActionWithPublications(thePubs, { forScriptHook : 
theScriptHook }) {
var theName = theScriptHook.name();
var theID = theScriptHook.id<http://thescripthook.id/>();
var theField = theScriptHook.fieldName();
var oldValues = theScriptHook.oldValues();
var newValues = theScriptHook.newValues();
var theKeys = [];
for (var aPub in thePubs) {
theKeys.push(aPub.citeKey);
}
var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.displayDialog("Name: " + theName + "\n" + "ID: " + theID + "\n" + "Cite 
Keys: " + theKeys + "\n" + "Field name: " + theField + "\n" + "Old values: " + 
oldValues + "\n" + "New values: " + newValues, { buttons : ["OK"], 
defaultButton : 1 });
}

It works for me, at least with the current nightly.

Christiaan


I’ve added some sample JXA script hooks on the Wiki.

Christiaan

___
Bibdesk-users mailing list
Bibdesk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-users


Re: [Bibdesk-users] JXA ScriptHook

2019-05-02 Thread Christiaan Hofman


> On 2 May 2019, at 18:55, Christiaan Hofman  wrote:
> 
> 
> 
>> On 2 May 2019, at 18:12, Christiaan Hofman > > wrote:
>> 
>> 
>> 
>>> On 2 May 2019, at 17:22, Mahmood Shafeie Zargar >> > wrote:
>>> 
>>> Hi,
>>> 
>>> I would like to know where I can find an example of a script hook written 
>>> in JavaScript. 
>>> 
>>> I have tried things like this to no avail:
>>> 
>>> functionperformBibDeskActionWithPublications(pubs, scriptHook) {
>>> 
>>> }
>>> 
>>> The function code runs, but no value is loaded in the parameters.
>>> 
>>> Thanks,
>>> Mah
>> 
>> 
>> I haven’t tried using JXA script hooks, but I think they should work. Though 
>> it could be JXA hangs BibDesk, because of bugs with JXA (that Apple says 
>> aren’t bugs but just how it works), that will be fixed in the next release.
>> 
>> I am not an expert on JS, but shouldn’t it be:
>> 
>> function performBibDeskActionWithPublications(pubs, 
>> {forScriptHook:scriptHook}) {
>>  
>> }
>> 
>> Christiaan
> 
> 
> Here is the JXA version for the sample script hook:
> 
> function performBibDeskActionWithPublications(thePubs, { forScriptHook : 
> theScriptHook }) {
>   var theName = theScriptHook.name();
>   var theID = theScriptHook.id ();
>   var theField = theScriptHook.fieldName();
>   var oldValues = theScriptHook.oldValues();
>   var newValues = theScriptHook.newValues();
>   var theKeys = [];
>   for (var aPub in thePubs) {
>   theKeys.push(aPub.citeKey);
>   }
>   var app = Application.currentApplication();
>   app.includeStandardAdditions = true;
>   app.displayDialog("Name: " + theName + "\n" + "ID: " + theID + "\n" + 
> "Cite Keys: " + theKeys + "\n" + "Field name: " + theField + "\n" + "Old 
> values: " + oldValues + "\n" + "New values: " + newValues, { buttons : 
> ["OK"], defaultButton : 1 });
> }
> 
> It works for me, at least with the current nightly.
> 
> Christiaan
> 


I’ve added some sample JXA script hooks on the Wiki.

Christiaan

___
Bibdesk-users mailing list
Bibdesk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-users


Re: [Bibdesk-users] JXA ScriptHook

2019-05-02 Thread Christiaan Hofman


> On 2 May 2019, at 18:12, Christiaan Hofman  wrote:
> 
> 
> 
>> On 2 May 2019, at 17:22, Mahmood Shafeie Zargar > > wrote:
>> 
>> Hi,
>> 
>> I would like to know where I can find an example of a script hook written in 
>> JavaScript. 
>> 
>> I have tried things like this to no avail:
>> 
>> functionperformBibDeskActionWithPublications(pubs, scriptHook) {
>> 
>> }
>> 
>> The function code runs, but no value is loaded in the parameters.
>> 
>> Thanks,
>> Mah
> 
> 
> I haven’t tried using JXA script hooks, but I think they should work. Though 
> it could be JXA hangs BibDesk, because of bugs with JXA (that Apple says 
> aren’t bugs but just how it works), that will be fixed in the next release.
> 
> I am not an expert on JS, but shouldn’t it be:
> 
> function performBibDeskActionWithPublications(pubs, 
> {forScriptHook:scriptHook}) {
>   
> }
> 
> Christiaan


Here is the JXA version for the sample script hook:

function performBibDeskActionWithPublications(thePubs, { forScriptHook : 
theScriptHook }) {
var theName = theScriptHook.name();
var theID = theScriptHook.id();
var theField = theScriptHook.fieldName();
var oldValues = theScriptHook.oldValues();
var newValues = theScriptHook.newValues();
var theKeys = [];
for (var aPub in thePubs) {
theKeys.push(aPub.citeKey);
}
var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.displayDialog("Name: " + theName + "\n" + "ID: " + theID + "\n" + 
"Cite Keys: " + theKeys + "\n" + "Field name: " + theField + "\n" + "Old 
values: " + oldValues + "\n" + "New values: " + newValues, { buttons : ["OK"], 
defaultButton : 1 });
}

It works for me, at least with the current nightly.

Christiaan

___
Bibdesk-users mailing list
Bibdesk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-users


Re: [Bibdesk-users] JXA ScriptHook

2019-05-02 Thread Christiaan Hofman


> On 2 May 2019, at 17:22, Mahmood Shafeie Zargar  wrote:
> 
> Hi,
> 
> I would like to know where I can find an example of a script hook written in 
> JavaScript. 
> 
> I have tried things like this to no avail:
> 
> functionperformBibDeskActionWithPublications(pubs, scriptHook) {
> 
> }
> 
> The function code runs, but no value is loaded in the parameters.
> 
> Thanks,
> Mah


I haven’t tried using JXA script hooks, but I think they should work. Though it 
could be JXA hangs BibDesk, because of bugs with JXA (that Apple says aren’t 
bugs but just how it works), that will be fixed in the next release.

I am not an expert on JS, but shouldn’t it be:

function performBibDeskActionWithPublications(pubs, {forScriptHook:scriptHook}) 
{

}

Christiaan

___
Bibdesk-users mailing list
Bibdesk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-users


[Bibdesk-users] JXA ScriptHook

2019-05-02 Thread Mahmood Shafeie Zargar
Hi,

I would like to know where I can find an example of a script hook written in 
JavaScript.

I have tried things like this to no avail:


functionperformBibDeskActionWithPublications(pubs, scriptHook) {


}


The function code runs, but no value is loaded in the parameters.


Thanks,

Mah

___
Bibdesk-users mailing list
Bibdesk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-users