I'm trying to create an AppleScript that creates hyperlinks on every linked image in InDesign.
This is what I have come up with so far.
tell application "Adobe InDesign CC 2017"
activate
tell active document
set grphicBoxs to all graphics of layer activeLayer
set myLinks to {}
repeat with I in grphicBoxs
set iLink to item link of i
set end of myLinks to iLink
end repeat
repeat with theLinkRef in myLinks
set theLinkName to ((name of theLinkRef) as string)
display dialog "theLinkName: " & theLinkName
set myHyperLink to "www.myURL"
set myHyperLinkName to "myURL name"
try
set hyperLinkPreSet to make hyperlink URL destination with properties `{name:myHyperLinkName, destination URL:myHyperLink}`
on error
set hyperLinkPreSet to hyperlink URL destination myHyperLinkName
end try
try
set hyperLinkObject to make hyperlink page item source with properties `{name:myHyperLinkName, source page item:rectangle theLinkName, hidden:false}`
on error
set TheHS to hyperlink page item source myHyperLinkName
end try
display dialog "hyperLinkObject:" & hyperLinkObject
make new hyperlink with properties `{destination:myHyperLink, source:hyperLinkObject, visible:false}`
end repeat
end tell
end tell
The expected result is that the hyperlink preset that is created is applied to the chosen object. But I get this error message.
Invalid value for parameter 'source' of method 'make'. Expected page
item, but received nothing.
Is there anyone here who has successfully created hyperlinks on linked objects who can help me?
Problem solved
set activeLayer to "Layer 1"
set counter to 1
tell application "Adobe InDesign CC 2017"
activate
tell active document
set grphicBoxs to all graphics of layer activeLayer
set myLinks to {}
repeat with i in grphicBoxs
set iLink to item link of i
set end of myLinks to iLink
end repeat
repeat with theLinkRef in myLinks
set theLinkName to ((name of theLinkRef) as string)
set theLinkNameNoext to text 1 thru ((offset of "." in theLinkName) - 1) of theLinkName
set myHyperLink to "http://macscripter.net"
set myHyperLinkName to theLinkNameNoext & " " & counter
make hyperlink with properties {name:myHyperLinkName, source:make hyperlink page item source with properties {source page item:rectangle counter}, destination:make hyperlink URL destination with properties {destination URL:myHyperLink}}
set counter to counter + 1
end repeat
end tell
end tell
Related
It seems not as easy as i thought it should be.
My Script fetches Link URL's from websites
As of now, the resulting URL's are just text and i need them to be put out as URL's (clipboard or variable) to paste them into an email message
I have tried various things from saving first to a rtf file and reading/pasting it to my email message body or copy and paste trough the clipboard.
Any help would be awesome as i can't get this solved since 2 days. Thanks
--prompt for keyword
display dialog "Keyword or Sentence" default answer "mad dog" buttons {"Done"} default button 1
set Keyword to text returned of the result
--create URL filter from Keyword
set my text item delimiters to " "
delay 0.2
set split_list to every text item of Keyword -- split in to list of everything between the spaces
set my text item delimiters to "-"
set Filter to (split_list as text) -- join, using the - as the delimter
--Open Pages
set site_url to "https://teespring.com/search?q=" & Keyword
tell application "Safari"
activate
open location site_url
end tell
-- wait until page loaded
property testingString : "Help" --Text on website to look for
set pageLoaded to false
tell application "Safari"
repeat while pageLoaded is false
set readyState to (do JavaScript "document.readyState" in document 1)
set pageText to text of document 1
if (readyState is "complete") and (pageText contains testingString) then set pageLoaded to true
delay 0.2
end repeat
end tell
-- get number of links
set theLinks to {}
tell application "Safari" to set num_links to (do JavaScript "document.links.length" in document 1)
set linkCounter to num_links - 1
-- retrieve the links
repeat with i from 0 to linkCounter
tell application "Safari" to set end of theLinks to do JavaScript "document.links[" & i & "].href" in document 1
end repeat
theLinks
set nonExcludedURLs to {}
--Filter URLs
repeat with i from 1 to length of theLinks
if item i of theLinks contains Filter then
set end of nonExcludedURLs to item i of theLinks
end if
end repeat
nonExcludedURLs
on page_loaded(timeout_value)
delay 2
repeat with i from 1 to the timeout_value
tell application "Safari"
if (do JavaScript "document.readyState" in document 1) is "complete" then
set nonExcludedURLs to {}
return true
else if i is the timeout_value then
return false
else
delay 1
end if
end tell
end repeat
return false
end page_loaded
Found the solution. Maybe i described the problem not very well.
I just needed to split the resulting url's from a block of text to single lines with the following code:
set Single_URLs to ""
repeat with this_line in nonExcludedURLs -- the URL's as block of text
set Single_URLs to Single_URLs & this_line & return --split into lines
end repeat
After I did a query in openoffice-base over a customized form I want to transfer a selected set of data into a template openoffice-calc table. I know I can access the data set in openoffice-calc via pressing the Data Source (F4) button but then I only get access over the query. The best solution would be after the database query over a form a button event is required to open a openoffice-calc table from the template and insert the data from the data set.
First go to Tools -> Macros -> Organize Macros -> LibreOffice Basic and add this code. Change the path of the template file.
Sub Copy_Record_To_Calc(oEvent)
Dim oForm
Dim templatePath As String
Dim oServiceManager As Object, oDesktop As Object
Dim oFileProperties As Object
Dim oDoc As Object, oSheet As Object, oCell As Object
Dim column As Integer
oForm = oEvent.Source.getModel().getParent()
If oForm.isAfterLast() Then
Print "Hey, you are after the last element."
Exit Sub
ElseIf oForm.isBeforeFirst() Then
Print "Hey, you are before the first element."
Exit Sub
End If
templatePath = "file:///C:/Users/JimStandard/Desktop/Untitled 2.ots"
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
Set oFileProperties(0) = new com.sun.star.beans.PropertyValue
oFileProperties(0).Name = "AsTemplate"
oFileProperties(0).Value = True
Set oDoc = oDesktop.loadComponentFromURL( _
templatePath, "_blank", 0, Array(oFileProperties))
oSheet = oDoc.Sheets(0)
For column = 1 to 2
oCell = oSheet.getCellByPosition(column - 1, 0)
oCell.String = oForm.getString(column)
Next column
End Sub
Then in form design mode, right-click on the button and choose Control. In the Events tab, click the three dots next to Execute action. Click Macro... and find the Copy_Record_To_Calc macro that you added.
Now turn design mode off. Go to a record and click the button. It will open the Calc template and copy the first two columns of the current record into column A and B of the spreadsheet.
See also:
Section 4.2.1 of Andrew Pitonyak's Base Macros (PDF)
ResultSet documentation
This thread gives an example of using a Calc template.
I have a apple script program that I am programming and I want the text the user sends to open an application, But I keep getting error messages saying "Can't get application {"name_of_app"} of <>. The code I very simple and I cant figure out the problem
set deReturnedItems to (display dialog "How many spam messages?" with icon stop default answer "" buttons {"Quit", "OK"} default button 2)
set xpp to text returned of deReturnedItems
set theReturnedItems to (display dialog "How many spam messages?" with icon stop default answer "" buttons {"Quit", "OK"} default button 2)
set amt to the text returned of theReturnedItems
set daReturnedItems to (display dialog "Last thing, what should the spam message say?" default answer "" buttons {"Quit", "OK"} default button 2)
set msg to the text returned of daReturnedItems
repeat [amt] times
tell application [xpp]
activate
tell application "System Events"
keystroke [msg]
keystroke return
end tell
end tell
end repeat
Get rid of those square brackets. Don't use them for variables. Use underscores before and after if you must, like:
repeat _amt_ times
…
end
Also, you need to check to make sure your variable is an integer before you use it in the repeat block.
Incidentally, when you set a variable and then include it in brackets, that's applescript syntax for set the string to a list. For example:
set [x, y, z] to "123"
return x
-- returns "1", and y is set to "2", and z is set to "3"
I'm using DynamicUpdateCommand inside a macro in this way:
sub addOrder
set choosen = ActiveDocument.Fields("NUMORD").GetPossibleValues
for i = 0 to choosen.Count - 1
set result = ActiveDocument.DynamicUpdateCommand("UPDATE * SET CHOOSE = 'S' WHERE NUMORD = '" & choosen.Item(i).text & "' " )
if result = false then
MsgBox result.ErrorMessage
end if
next
end sub
Dinamic Data Update is enabled.
It works, but, when I close QlikView and reopen it, it doesn't work anymore. Even if try reloading.
I empirically realized that to make it work again I need to click the "Save" button, even without changing anything...
How can I solve this little issue? Maybe is it connected with RAM and way of saving .qvw file to the file system?
Many thanks!
Without any other solution I ended with this workaround, which saves the document programmatically on document opening:
Document Properties... > Triggers > Document Event Triggers > OnOpen > Add Action(s)... > Add > External > Run macro > set Macro name = reactivateDynamicUpdateCommand
Tools > Edit Module...: add this subroutine:
sub reactivateDynamicUpdateCommand
' I know, it's weird
'... but needed to reactivate DynamicUpdateCommand functionality after a restart
ActiveDocument.Save
end sub
It works, though a better solution would be preferred.
Starting from version 11 Dynamic Update can be done as Actions rather than through VB macro. It is preferable to use Actions when possible. However, sometimes even using Dynamic Update action I noticed freezes similar to what you described. I ended up adding one more dummy action right after Dynamic Update (e.g. assigning a value to dummy variable or adding Selection -> Back action to compensate triggering OnSelect).
I'd like to extend the MS Excel 2010 by adding some more "Additional Cell Actions". (accessible via cell right-click > Additional Cell Actions). Specifically, I'd like Excel to:
recognize five-to-eight digit numbers as Part Numbers with action: "Open URL to technical docs"
recognize string "OR ## #####" (# for digit) as Order Reference with actions: "Open spec file" and "Open material file" (both Excel files located at specified paths in the intranet)
Now, I have no idea how to program this. I suspect that some XML snippet is needed and probably some VB code too. VB code wouldn't be a problem - I have macros doing those functionalities done for Excel 2003 - but I have no idea where to place it.
Please give me some pointers, I've asked Google but can't get the answer, seems that "Additional Actions" is pretty common phrase :)
This can be achieved by adding a right click event handler to the workbook
In the Workbook module add this code
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim cBut As CommandBarButton
Dim v As Variant
On Error Resume Next
v = Target
' Remove any previously added menu items
Application.CommandBars("Cell").Controls("Open URL to technical docs").Delete
Application.CommandBars("Cell").Controls("Open material file").Delete
' save cell value for use by called macro
CellValue = v
' If cell matches criteria add menu item and set macro to call on click
If IsNumeric(v) Then
If v >= 10000 And v <= 99999999 Then
Set cBut = Application.CommandBars("Cell").Controls.Add(Temporary:=True)
With cBut
.Caption = "Open URL to technical docs"
.Style = msoButtonCaption
.OnAction = "OpenRef"
End With
End If
ElseIf v Like "OR ## #####" Then
Set cBut = Application.CommandBars("Cell").Controls.Add(Temporary:=True)
With cBut
.Caption = "Open material file"
.Style = msoButtonCaption
.OnAction = "OpenMat"
End With
End If
End Sub
In a standard module add this code
Public CellValue As Variant
' replace MsgBox code with your logic to open files
Sub OpenRef()
MsgBox "Open Reference Doc code here for " & CellValue
End Sub
Sub OpenMat()
MsgBox "Open Material File code here for " & CellValue
End Sub